-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle multiple headers with the same name
Pushes the fixes in dropwizard/dropwizard#8008 upstream into logback-access, where they probably should be. Unfortunately `HttpGetUtil` uses `HttpURLConnection`, which makes it hard to write a test for this because `HttpURLConnection` combines the headers for you.
- Loading branch information
Showing
3 changed files
with
32 additions
and
23 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
logback-access-jetty12/src/main/java/ch/qos/logback/access/jetty/HeaderUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ch.qos.logback.access.jetty; | ||
|
||
import org.eclipse.jetty.http.HttpField; | ||
import org.eclipse.jetty.http.HttpFields; | ||
|
||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
class HeaderUtil { | ||
static Map<String, String> buildHeaderMap(HttpFields headers) { | ||
Map<String, String> requestHeaderMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); | ||
for (HttpField f : headers) { | ||
String existing = requestHeaderMap.get(f.getName()); | ||
String value = combine(existing, f.getValue()); | ||
requestHeaderMap.put(f.getName(), value); | ||
} | ||
return requestHeaderMap; | ||
} | ||
|
||
private static String combine(String existing, String field) { | ||
if (existing == null) { | ||
return field; | ||
} else { | ||
return existing + "," + field; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters