Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r9529 r9807 12 12 import java.net.HttpURLConnection; 13 13 import java.net.URL; 14 import java.util.Collections; 14 15 import java.util.List; 15 16 import java.util.Locale; 16 17 import java.util.Map; 18 import java.util.Map.Entry; 17 19 import java.util.Scanner; 18 20 import java.util.TreeMap; … … 385 387 /** 386 388 * Returns an unmodifiable Map mapping header keys to a List of header values. 389 * As per RFC 2616, section 4.2 header names are case insensitive, so returned map is also case insensitive 387 390 * @return unmodifiable Map mapping header keys to a List of header values 388 391 * @see HttpURLConnection#getHeaderFields() … … 390 393 */ 391 394 public Map<String, List<String>> getHeaderFields() { 392 return connection.getHeaderFields(); 395 // returned map from HttpUrlConnection is case sensitive, use case insensitive TreeMap to conform to RFC 2616 396 Map<String, List<String>> ret = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); 397 for(Entry<String, List<String>> e: connection.getHeaderFields().entrySet()) { 398 if (e.getKey() != null) { 399 ret.put(e.getKey(), e.getValue()); 400 } 401 } 402 return Collections.unmodifiableMap(ret); 393 403 } 394 404 -
trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
r9669 r9807 69 69 assertThat(response.getHeaderField("Content-TYPE"), is("application/json")); 70 70 assertThat(response.getHeaderFields().get("Content-Type"), is(Collections.singletonList("application/json"))); 71 assertThat(response.getHeaderFields().get("Content-TYPE"), nullValue());71 assertThat(response.getHeaderFields().get("Content-TYPE"), is(Collections.singletonList("application/json"))); 72 72 try (final InputStream in = response.getContent(); 73 73 final JsonReader json = JsonProvider.provider().createReader(in)) {
Note:
See TracChangeset
for help on using the changeset viewer.