Class HeaderAccessUtils


  • public final class HeaderAccessUtils
    extends Object
    This class is useful for accessing HTTP headers in a case-insensitive manner. This is necessary for compatibility with OkHttp 3.3.0+, as that lower-cases header names whereas we use constants from HttpHeaders where header names are in Train-Case. Note that the HTTP specification does not place restrictions on casing of headers.
    • Method Detail

      • shortcircuitingCaseInsensitiveContainsEntry

        public static boolean shortcircuitingCaseInsensitiveContainsEntry​(Map<String,​Collection<String>> headers,
                                                                          String header,
                                                                          String value)
        Compares the keys of the map to the header in a case-insensitive manner; upon finding a match, compares the associated collection of strings from the map with the value, returning true iff this contains a match. If no key matches, this method returns false. This can be implemented in terms of shortcircuitingCaseInsensitiveGet, but suffered a performance regression in benchmarking. This is a hot code path, so speed is important. As a precondition: the headers map should NOT contain distinct keys differing only in case. (This is true as far as our use-case is concerned.)
      • shortcircuitingCaseInsensitiveGet

        public static Collection<String> shortcircuitingCaseInsensitiveGet​(Map<String,​Collection<String>> headers,
                                                                           String header)
        Compares the keys of the map to the header in a case-insensitive manner. Upon finding a match, returns the associated collection of strings. Returns an empty collection if the key is not present in the map. As a precondition: the headers map should NOT contain distinct keys differing only in case. (This is true as far as our use-case is concerned.)