Class HttpHeaders

  • All Implemented Interfaces:
    java.lang.Iterable<HttpHeader>

    public class HttpHeaders
    extends java.lang.Object
    implements java.lang.Iterable<HttpHeader>
    A collection of headers on an HTTP request or response.
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpHeaders()
      Create an empty HttpHeaders instance.
      HttpHeaders​(java.lang.Iterable<HttpHeader> headers)
      Create a HttpHeaders instance with the provided initial headers.
      HttpHeaders​(java.util.Map<java.lang.String,​java.lang.String> headers)
      Create a HttpHeaders instance with the provided initial headers.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      HttpHeader get​(java.lang.String name)
      Gets the header for the provided header name.
      int getSize()
      Gets the number of headers in the collection.
      java.lang.String getValue​(java.lang.String name)
      Get the value for the provided header name.
      java.lang.String[] getValues​(java.lang.String name)
      Get the values for the provided header name.
      java.util.Iterator<HttpHeader> iterator()
      HttpHeaders put​(java.lang.String name, java.lang.String value)
      Sets a header with the given name and value.
      HttpHeader remove​(java.lang.String name)
      Removes the header with the provided header name.
      java.util.Map<java.lang.String,​java.lang.String> toMap()
      Gets a Map representation of the HttpHeaders collection.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Constructor Detail

      • HttpHeaders

        public HttpHeaders()
        Create an empty HttpHeaders instance.
      • HttpHeaders

        public HttpHeaders​(java.util.Map<java.lang.String,​java.lang.String> headers)
        Create a HttpHeaders instance with the provided initial headers.
        Parameters:
        headers - the map of initial headers
      • HttpHeaders

        public HttpHeaders​(java.lang.Iterable<HttpHeader> headers)
        Create a HttpHeaders instance with the provided initial headers.
        Parameters:
        headers - the collection of initial headers
    • Method Detail

      • getSize

        public int getSize()
        Gets the number of headers in the collection.
        Returns:
        the number of headers in this collection.
      • put

        public HttpHeaders put​(java.lang.String name,
                               java.lang.String value)
        Sets a header with the given name and value.

        If header with same name already exists then the value will be overwritten.

        Parameters:
        name - the name
        value - the value
        Returns:
        The updated HttpHeaders object
      • get

        public HttpHeader get​(java.lang.String name)
        Gets the header for the provided header name. Null is returned if the header isn't found.
        Parameters:
        name - the name of the header to find.
        Returns:
        the header if found, null otherwise.
      • remove

        public HttpHeader remove​(java.lang.String name)
        Removes the header with the provided header name. Null is returned if the header isn't found.
        Parameters:
        name - the name of the header to remove.
        Returns:
        the header if removed, null otherwise.
      • getValue

        public java.lang.String getValue​(java.lang.String name)
        Get the value for the provided header name. Null is returned if the header name isn't found.
        Parameters:
        name - the name of the header whose value is being retrieved.
        Returns:
        the value of the header, or null if the header isn't found
      • getValues

        public java.lang.String[] getValues​(java.lang.String name)
        Get the values for the provided header name. Null is returned if the header name isn't found.

        This returns getValue split by comma.

        Parameters:
        name - the name of the header whose value is being retrieved.
        Returns:
        the values of the header, or null if the header isn't found
      • toMap

        public java.util.Map<java.lang.String,​java.lang.String> toMap()
        Gets a Map representation of the HttpHeaders collection.
        Returns:
        the headers as map
      • iterator

        public java.util.Iterator<HttpHeader> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<HttpHeader>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object