Class HttpHeaders


  • public class HttpHeaders
    extends java.lang.Object
    A read-only view of a set of HTTP headers.

    This class mimics the java.net.http.HttpHeaders added in Java 11.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<java.lang.String> allValues​(java.lang.String name)
      Returns an unmodifiable List of all of the header string values of the given named header.
      protected boolean canEqual​(java.lang.Object other)  
      boolean equals​(java.lang.Object o)  
      java.util.Optional<java.lang.String> firstValue​(java.lang.String name)
      Returns an Optional containing the first header string value of the given named (and possibly multi-valued) header.
      int hashCode()  
      java.util.Map<java.lang.String,​java.util.List<java.lang.String>> map()
      Returns an unmodifiable Map view of this HttpHeaders.
      static HttpHeaders of​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headerMap)
      Returns an HttpHeaders instance initialized from the given map.
      java.lang.String toString()
      Returns this HttpHeaders as a string.
      HttpHeaders withAdditionalHeader​(java.lang.String name, java.lang.String value)
      Returns a new HttpHeaders instance containing the headers of the current instance plus the provided header.
      HttpHeaders withAdditionalHeader​(java.lang.String name, java.util.List<java.lang.String> values)
      Returns a new HttpHeaders instance containing the headers of the current instance plus the provided header.
      HttpHeaders withAdditionalHeaders​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headerMap)
      Returns a new HttpHeaders instance containing the headers of the current instance plus the provided headers.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • of

        public static HttpHeaders of​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headerMap)
        Returns an HttpHeaders instance initialized from the given map.
        Parameters:
        headerMap - the map containing the header names and values
        Returns:
        an HttpHeaders instance containing the given headers
        Throws:
        java.lang.NullPointerException - if headerMap is null
      • withAdditionalHeader

        public HttpHeaders withAdditionalHeader​(java.lang.String name,
                                                java.lang.String value)
        Returns a new HttpHeaders instance containing the headers of the current instance plus the provided header.
        Parameters:
        name - the name of the header to add
        value - the value of the header to add
        Returns:
        the new HttpHeaders instance
        Throws:
        java.lang.NullPointerException - if name or value is null
      • withAdditionalHeader

        public HttpHeaders withAdditionalHeader​(java.lang.String name,
                                                java.util.List<java.lang.String> values)
        Returns a new HttpHeaders instance containing the headers of the current instance plus the provided header.
        Parameters:
        name - the name of the header to add
        values - the values of the header to add
        Returns:
        the new HttpHeaders instance
        Throws:
        java.lang.NullPointerException - if name or values is null
      • withAdditionalHeaders

        public HttpHeaders withAdditionalHeaders​(java.util.Map<java.lang.String,​java.util.List<java.lang.String>> headerMap)
        Returns a new HttpHeaders instance containing the headers of the current instance plus the provided headers.
        Parameters:
        headerMap - the map containing the headers to add
        Returns:
        the new HttpHeaders instance
        Throws:
        java.lang.NullPointerException - if headerMap is null
      • allValues

        public java.util.List<java.lang.String> allValues​(java.lang.String name)
        Returns an unmodifiable List of all of the header string values of the given named header. Always returns a List, which may be empty if the header is not present.
        Parameters:
        name - the header name
        Returns:
        a List of headers string values
      • firstValue

        public java.util.Optional<java.lang.String> firstValue​(java.lang.String name)
        Returns an Optional containing the first header string value of the given named (and possibly multi-valued) header. If the header is not present, then the returned Optional is empty.
        Parameters:
        name - the header name
        Returns:
        an Optional<String> containing the first named header string value, if present
      • map

        public java.util.Map<java.lang.String,​java.util.List<java.lang.String>> map()
        Returns an unmodifiable Map view of this HttpHeaders.
        Returns:
        the Map
      • toString

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

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • canEqual

        protected boolean canEqual​(java.lang.Object other)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object