Ignore:
Timestamp:
2016-02-15T23:39:36+01:00 (4 years ago)
Author:
wiktorn
Message:

Make map returned by getHeaderFields() case insensitive.

RFC 2616, section 4.2, specifies that header names are case insensitive. This is properly handled by getHeaderField(...) in HttpUrlConnection, but in case of getHeaderFields() Map returned by Oracle JDK is case sensitive. By using case insentive map we avoid bigger refactoring of all usages, to use getHeaderField(...) where appropiate.

See #12235: Java Web Start cache returns all headers as lowercase, when real server return mixed case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/HttpClient.java

    r9529 r9807  
    1212import java.net.HttpURLConnection;
    1313import java.net.URL;
     14import java.util.Collections;
    1415import java.util.List;
    1516import java.util.Locale;
    1617import java.util.Map;
     18import java.util.Map.Entry;
    1719import java.util.Scanner;
    1820import java.util.TreeMap;
     
    385387        /**
    386388         * 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
    387390         * @return unmodifiable Map mapping header keys to a List of header values
    388391         * @see HttpURLConnection#getHeaderFields()
     
    390393         */
    391394        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);
    393403        }
    394404
Note: See TracChangeset for help on using the changeset viewer.