Class HttpHeaders


  • public abstract class HttpHeaders
    extends Object
    A read-only view of a set of HTTP headers.
    Incubating Feature. Will be removed in a future release.

    The methods of this class ( that accept a String header name ), and the Map returned by the map method, operate without regard to case when retrieving the header value.

    HttpHeaders instances are immutable.

    Since:
    9
    • Constructor Detail

      • HttpHeaders

        protected HttpHeaders()
        Creates an HttpHeaders.
    • Method Detail

      • firstValue

        public Optional<String> firstValue​(String name)
        Returns an Optional containing the first value of the given named (and possibly multi-valued) header. If the header is not present, then the returned Optional is empty.
        Implementation Requirements:
        The default implementation invokes allValues(name).stream().findFirst()
        Parameters:
        name - the header name
        Returns:
        an Optional<String> for the first named value
      • firstValueAsLong

        public OptionalLong firstValueAsLong​(String name)
        Returns an OptionalLong containing the first value of the named header field. If the header is not present, then the Optional is empty. If the header is present but contains a value that does not parse as a Long value, then an exception is thrown.
        Implementation Requirements:
        The default implementation invokes allValues(name).stream().mapToLong(Long::valueOf).findFirst()
        Parameters:
        name - the header name
        Returns:
        an OptionalLong
        Throws:
        NumberFormatException - if a value is found, but does not parse as a Long
      • allValues

        public List<String> allValues​(String name)
        Returns an unmodifiable List of all of the values of the given named header. Always returns a List, which may be empty if the header is not present.
        Implementation Requirements:
        The default implementation invokes, among other things, the map().get(name) to retrieve the list of header values.
        Parameters:
        name - the header name
        Returns:
        a List of String values
      • map

        public abstract Map<String,List<String>> map()
        Returns an unmodifiable multi Map view of this HttpHeaders.
        Returns:
        the Map
      • equals

        public final boolean equals​(Object obj)
        Tests this HTTP headers instance for equality with the given object.

        If the given object is not an HttpHeaders then this method returns false. Two HTTP headers are equal if each of their corresponding maps are equal.

        This method satisfies the general contract of the Object.equals method.

        Overrides:
        equals in class Object
        Parameters:
        obj - the object to which this object is to be compared
        Returns:
        true if, and only if, the given object is an HttpHeaders that is equal to this HTTP headers
        See Also:
        Object.hashCode(), HashMap
      • toString

        public String toString()
        Returns this HTTP headers as a string.
        Overrides:
        toString in class Object
        Returns:
        a string describing the HTTP headers