Class HttpHeaders

  • All Implemented Interfaces:
    java.lang.Cloneable, java.util.Map<java.lang.String,​java.lang.Object>

    public class HttpHeaders
    extends GenericData
    Stores HTTP headers used in an HTTP request or response, as defined in Header Field Definitions.

    null is not allowed as a name or value of a header. Names are case-insensitive.

    Implementation is not thread-safe.

    Since:
    1.0
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  HttpHeaders.HeaderParsingFakeLevelHttpRequest
      LowLevelHttpRequest which will call the .parseHeader() method for every header added.
      private static class  HttpHeaders.ParseHeaderState
      • Nested classes/interfaces inherited from class java.util.AbstractMap

        java.util.AbstractMap.SimpleEntry<K extends java.lang.Object,​V extends java.lang.Object>, java.util.AbstractMap.SimpleImmutableEntry<K extends java.lang.Object,​V extends java.lang.Object>
      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K extends java.lang.Object,​V extends java.lang.Object>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.lang.String> accept
      "Accept" header.
      private java.util.List<java.lang.String> acceptEncoding
      "Accept-Encoding" header.
      private java.util.List<java.lang.Long> age
      "Age" header.
      private java.util.List<java.lang.String> authenticate
      "WWW-Authenticate" header.
      private java.util.List<java.lang.String> authorization
      "Authorization" header.
      private java.util.List<java.lang.String> cacheControl
      "Cache-Control" header.
      private java.util.List<java.lang.String> contentEncoding
      "Content-Encoding" header.
      private java.util.List<java.lang.Long> contentLength
      "Content-Length" header.
      private java.util.List<java.lang.String> contentMD5
      "Content-MD5" header.
      private java.util.List<java.lang.String> contentRange
      "Content-Range" header.
      private java.util.List<java.lang.String> contentType
      "Content-Type" header.
      private java.util.List<java.lang.String> cookie
      "Cookie" header.
      private java.util.List<java.lang.String> date
      "Date" header.
      private java.util.List<java.lang.String> etag
      "ETag" header.
      private java.util.List<java.lang.String> expires
      "Expires" header.
      private java.util.List<java.lang.String> ifMatch
      "If-Match" header.
      private java.util.List<java.lang.String> ifModifiedSince
      "If-Modified-Since" header.
      private java.util.List<java.lang.String> ifNoneMatch
      "If-None-Match" header.
      private java.util.List<java.lang.String> ifRange
      "If-Range" header.
      private java.util.List<java.lang.String> ifUnmodifiedSince
      "If-Unmodified-Since" header.
      private java.util.List<java.lang.String> lastModified
      "Last-Modified" header.
      private java.util.List<java.lang.String> location
      "Location" header.
      private java.util.List<java.lang.String> mimeVersion
      "MIME-Version" header.
      private java.util.List<java.lang.String> range
      "Range" header.
      private java.util.List<java.lang.String> retryAfter
      "Retry-After" header.
      private java.util.List<java.lang.String> userAgent
      "User-Agent" header.
      private java.util.List<java.lang.String> warning
      "Warning" header.
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpHeaders()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private static void addHeader​(java.util.logging.Logger logger, java.lang.StringBuilder logbuf, java.lang.StringBuilder curlbuf, LowLevelHttpRequest lowLevelHttpRequest, java.lang.String name, java.lang.Object value, java.io.Writer writer)  
      HttpHeaders addWarning​(java.lang.String warning)
      Adds the "Warning" header or null for none.
      HttpHeaders clone()
      Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.
      void fromHttpHeaders​(HttpHeaders headers)
      Puts all headers of the HttpHeaders object into this HttpHeaders object.
      void fromHttpResponse​(LowLevelHttpResponse response, java.lang.StringBuilder logger)
      Puts all headers of the LowLevelHttpResponse into this HttpHeaders object.
      java.lang.String getAccept()
      Returns the first "Accept" header or null for none.
      java.lang.String getAcceptEncoding()
      Returns the first "Accept-Encoding" header or null for none.
      java.lang.Long getAge()
      Returns the first "Age" header or null for none.
      private <T> java.util.List<T> getAsList​(T passedValue)
      Returns the list value to use for the given parameter passed to the setter method.
      java.lang.String getAuthenticate()
      Returns the first "WWW-Authenticate" header or null for none.
      java.util.List<java.lang.String> getAuthenticateAsList()
      Returns all "WWW-Authenticate" headers or null for none.
      java.lang.String getAuthorization()
      Returns the first "Authorization" header or null for none.
      java.util.List<java.lang.String> getAuthorizationAsList()
      Returns all "Authorization" headers or null for none.
      java.lang.String getCacheControl()
      Returns the first "Cache-Control" header or null for none.
      java.lang.String getContentEncoding()
      Returns the first "Content-Encoding" header or null for none.
      java.lang.Long getContentLength()
      Returns the first "Content-Length" header or null for none.
      java.lang.String getContentMD5()
      Returns the first "Content-MD5" header or null for none.
      java.lang.String getContentRange()
      Returns the first "Content-Range" header or null for none.
      java.lang.String getContentType()
      Returns the first "Content-Type" header or null for none.
      java.lang.String getCookie()
      Returns the first "Cookie" header or null for none.
      java.lang.String getDate()
      Returns the first "Date" header or null for none.
      java.lang.String getETag()
      Returns the first "ETag" header or null for none.
      java.lang.String getExpires()
      Returns the first "Expires" header or null for none.
      java.lang.String getFirstHeaderStringValue​(java.lang.String name)
      Returns the first header string value for the given header name.
      private <T> T getFirstHeaderValue​(java.util.List<T> internalValue)
      Returns the first header value based on the given internal list value.
      java.util.List<java.lang.String> getHeaderStringValues​(java.lang.String name)
      Returns an unmodifiable list of the header string values for the given header name.
      java.lang.String getIfMatch()
      Returns the first "If-Match" header or null for none.
      java.lang.String getIfModifiedSince()
      Returns the first "If-Modified-Since" header or null for none.
      java.lang.String getIfNoneMatch()
      Returns the first "If-None-Match" header or null for none.
      java.lang.String getIfRange()
      Returns the first "If-Range" header or null for none.
      java.lang.String getIfUnmodifiedSince()
      Returns the first "If-Unmodified-Since" header or null for none.
      java.lang.String getLastModified()
      Returns the first "Last-Modified" header or null for none.
      java.lang.String getLocation()
      Returns the first "Location" header or null for none.
      java.lang.String getMimeVersion()
      Returns the first "MIME-Version" header or null for none.
      java.lang.String getRange()
      Returns the first "Range" header or null for none.
      java.lang.String getRetryAfter()
      Returns the first "Retry-After" header or null for none.
      java.lang.String getUserAgent()
      Returns the first "User-Agent" header or null for none.
      java.util.List<java.lang.String> getWarning()
      Returns all "Warning" headers or null for none.
      (package private) void parseHeader​(java.lang.String headerName, java.lang.String headerValue, HttpHeaders.ParseHeaderState state)
      Parses the specified case-insensitive header pair into this HttpHeaders instance.
      private static java.lang.Object parseValue​(java.lang.reflect.Type valueType, java.util.List<java.lang.reflect.Type> context, java.lang.String value)  
      (package private) static void serializeHeaders​(HttpHeaders headers, java.lang.StringBuilder logbuf, java.lang.StringBuilder curlbuf, java.util.logging.Logger logger, LowLevelHttpRequest lowLevelHttpRequest)
      Serializes headers to an LowLevelHttpRequest.
      (package private) static void serializeHeaders​(HttpHeaders headers, java.lang.StringBuilder logbuf, java.lang.StringBuilder curlbuf, java.util.logging.Logger logger, LowLevelHttpRequest lowLevelHttpRequest, java.io.Writer writer)  
      static void serializeHeadersForMultipartRequests​(HttpHeaders headers, java.lang.StringBuilder logbuf, java.util.logging.Logger logger, java.io.Writer writer)
      Serializes headers to an Writer for Multi-part requests.
      HttpHeaders set​(java.lang.String fieldName, java.lang.Object value)
      Sets the given field value (may be null) for the given field name.
      HttpHeaders setAccept​(java.lang.String accept)
      Sets the "Accept" header or null for none.
      HttpHeaders setAcceptEncoding​(java.lang.String acceptEncoding)
      Sets the "Accept-Encoding" header or null for none.
      HttpHeaders setAge​(java.lang.Long age)
      Sets the "Age" header or null for none.
      HttpHeaders setAuthenticate​(java.lang.String authenticate)
      Sets the "WWW-Authenticate" header or null for none.
      HttpHeaders setAuthorization​(java.lang.String authorization)
      Sets the "Authorization" header or null for none.
      HttpHeaders setAuthorization​(java.util.List<java.lang.String> authorization)
      Sets the "Authorization" header or null for none.
      HttpHeaders setBasicAuthentication​(java.lang.String username, java.lang.String password)
      Sets the authorization header as specified in Basic Authentication Scheme.
      HttpHeaders setCacheControl​(java.lang.String cacheControl)
      Sets the "Cache-Control" header or null for none.
      HttpHeaders setContentEncoding​(java.lang.String contentEncoding)
      Sets the "Content-Encoding" header or null for none.
      HttpHeaders setContentLength​(java.lang.Long contentLength)
      Sets the "Content-Length" header or null for none.
      HttpHeaders setContentMD5​(java.lang.String contentMD5)
      Sets the "Content-MD5" header or null for none.
      HttpHeaders setContentRange​(java.lang.String contentRange)
      Sets the "Content-Range" header or null for none.
      HttpHeaders setContentType​(java.lang.String contentType)
      Sets the "Content-Type" header or null for none.
      HttpHeaders setCookie​(java.lang.String cookie)
      Sets the "Cookie" header or null for none.
      HttpHeaders setDate​(java.lang.String date)
      Sets the "Date" header or null for none.
      HttpHeaders setETag​(java.lang.String etag)
      Sets the "ETag" header or null for none.
      HttpHeaders setExpires​(java.lang.String expires)
      Sets the "Expires" header or null for none.
      HttpHeaders setIfMatch​(java.lang.String ifMatch)
      Sets the "If-Match" header or null for none.
      HttpHeaders setIfModifiedSince​(java.lang.String ifModifiedSince)
      Sets the "If-Modified-Since" header or null for none.
      HttpHeaders setIfNoneMatch​(java.lang.String ifNoneMatch)
      Sets the "If-None-Match" header or null for none.
      HttpHeaders setIfRange​(java.lang.String ifRange)
      Sets the "If-Range" header or null for none.
      HttpHeaders setIfUnmodifiedSince​(java.lang.String ifUnmodifiedSince)
      Sets the "If-Unmodified-Since" header or null for none.
      HttpHeaders setLastModified​(java.lang.String lastModified)
      Sets the "Last-Modified" header or null for none.
      HttpHeaders setLocation​(java.lang.String location)
      Sets the "Location" header or null for none.
      HttpHeaders setMimeVersion​(java.lang.String mimeVersion)
      Sets the "MIME-Version" header or null for none.
      HttpHeaders setRange​(java.lang.String range)
      Sets the "Range" header or null for none.
      HttpHeaders setRetryAfter​(java.lang.String retryAfter)
      Sets the "Retry-After" header or null for none.
      HttpHeaders setUserAgent​(java.lang.String userAgent)
      Sets the "User-Agent" header or null for none.
      private static java.lang.String toStringValue​(java.lang.Object headerValue)
      Returns the string header value for the given header value as an object.
      • Methods inherited from class java.util.AbstractMap

        clear, containsKey, containsValue, isEmpty, keySet, size, values
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Map

        compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
    • Field Detail

      • accept

        private java.util.List<java.lang.String> accept
        "Accept" header.
      • acceptEncoding

        private java.util.List<java.lang.String> acceptEncoding
        "Accept-Encoding" header.
      • authorization

        private java.util.List<java.lang.String> authorization
        "Authorization" header.
      • cacheControl

        private java.util.List<java.lang.String> cacheControl
        "Cache-Control" header.
      • contentEncoding

        private java.util.List<java.lang.String> contentEncoding
        "Content-Encoding" header.
      • contentLength

        private java.util.List<java.lang.Long> contentLength
        "Content-Length" header.
      • contentMD5

        private java.util.List<java.lang.String> contentMD5
        "Content-MD5" header.
      • contentRange

        private java.util.List<java.lang.String> contentRange
        "Content-Range" header.
      • contentType

        private java.util.List<java.lang.String> contentType
        "Content-Type" header.
      • cookie

        private java.util.List<java.lang.String> cookie
        "Cookie" header.
      • date

        private java.util.List<java.lang.String> date
        "Date" header.
      • etag

        private java.util.List<java.lang.String> etag
        "ETag" header.
      • expires

        private java.util.List<java.lang.String> expires
        "Expires" header.
      • ifModifiedSince

        private java.util.List<java.lang.String> ifModifiedSince
        "If-Modified-Since" header.
      • ifMatch

        private java.util.List<java.lang.String> ifMatch
        "If-Match" header.
      • ifNoneMatch

        private java.util.List<java.lang.String> ifNoneMatch
        "If-None-Match" header.
      • ifUnmodifiedSince

        private java.util.List<java.lang.String> ifUnmodifiedSince
        "If-Unmodified-Since" header.
      • ifRange

        private java.util.List<java.lang.String> ifRange
        "If-Range" header.
      • lastModified

        private java.util.List<java.lang.String> lastModified
        "Last-Modified" header.
      • location

        private java.util.List<java.lang.String> location
        "Location" header.
      • mimeVersion

        private java.util.List<java.lang.String> mimeVersion
        "MIME-Version" header.
      • range

        private java.util.List<java.lang.String> range
        "Range" header.
      • retryAfter

        private java.util.List<java.lang.String> retryAfter
        "Retry-After" header.
      • userAgent

        private java.util.List<java.lang.String> userAgent
        "User-Agent" header.
      • warning

        private java.util.List<java.lang.String> warning
        "Warning" header.
      • authenticate

        private java.util.List<java.lang.String> authenticate
        "WWW-Authenticate" header.
      • age

        private java.util.List<java.lang.Long> age
        "Age" header.
    • Constructor Detail

      • HttpHeaders

        public HttpHeaders()
    • Method Detail

      • clone

        public HttpHeaders clone()
        Description copied from class: GenericData
        Makes a "deep" clone of the generic data, in which the clone is completely independent of the original.
        Overrides:
        clone in class GenericData
      • set

        public HttpHeaders set​(java.lang.String fieldName,
                               java.lang.Object value)
        Description copied from class: GenericData
        Sets the given field value (may be null) for the given field name. Any existing value for the field will be overwritten. It may be more slightly more efficient than GenericData.put(String, Object) because it avoids accessing the field's original value.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Overrides:
        set in class GenericData
      • getAccept

        public final java.lang.String getAccept()
        Returns the first "Accept" header or null for none.
        Since:
        1.5
      • setAccept

        public HttpHeaders setAccept​(java.lang.String accept)
        Sets the "Accept" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getAcceptEncoding

        public final java.lang.String getAcceptEncoding()
        Returns the first "Accept-Encoding" header or null for none.
        Since:
        1.5
      • setAcceptEncoding

        public HttpHeaders setAcceptEncoding​(java.lang.String acceptEncoding)
        Sets the "Accept-Encoding" header or null for none.

        By default, this is "gzip".

        Since:
        1.5
      • getAuthorization

        public final java.lang.String getAuthorization()
        Returns the first "Authorization" header or null for none.
        Since:
        1.5
      • getAuthorizationAsList

        public final java.util.List<java.lang.String> getAuthorizationAsList()
        Returns all "Authorization" headers or null for none.
        Since:
        1.13
      • setAuthorization

        public HttpHeaders setAuthorization​(java.lang.String authorization)
        Sets the "Authorization" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • setAuthorization

        public HttpHeaders setAuthorization​(java.util.List<java.lang.String> authorization)
        Sets the "Authorization" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.13
      • getCacheControl

        public final java.lang.String getCacheControl()
        Returns the first "Cache-Control" header or null for none.
        Since:
        1.5
      • setCacheControl

        public HttpHeaders setCacheControl​(java.lang.String cacheControl)
        Sets the "Cache-Control" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getContentEncoding

        public final java.lang.String getContentEncoding()
        Returns the first "Content-Encoding" header or null for none.
        Since:
        1.5
      • setContentEncoding

        public HttpHeaders setContentEncoding​(java.lang.String contentEncoding)
        Sets the "Content-Encoding" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getContentLength

        public final java.lang.Long getContentLength()
        Returns the first "Content-Length" header or null for none.
        Since:
        1.5
      • setContentLength

        public HttpHeaders setContentLength​(java.lang.Long contentLength)
        Sets the "Content-Length" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getContentMD5

        public final java.lang.String getContentMD5()
        Returns the first "Content-MD5" header or null for none.
        Since:
        1.5
      • setContentMD5

        public HttpHeaders setContentMD5​(java.lang.String contentMD5)
        Sets the "Content-MD5" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getContentRange

        public final java.lang.String getContentRange()
        Returns the first "Content-Range" header or null for none.
        Since:
        1.5
      • setContentRange

        public HttpHeaders setContentRange​(java.lang.String contentRange)
        Sets the "Content-Range" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getContentType

        public final java.lang.String getContentType()
        Returns the first "Content-Type" header or null for none.
        Since:
        1.5
      • setContentType

        public HttpHeaders setContentType​(java.lang.String contentType)
        Sets the "Content-Type" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getCookie

        public final java.lang.String getCookie()
        Returns the first "Cookie" header or null for none.

        See Cookie Specification.

        Since:
        1.6
      • setCookie

        public HttpHeaders setCookie​(java.lang.String cookie)
        Sets the "Cookie" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.6
      • getDate

        public final java.lang.String getDate()
        Returns the first "Date" header or null for none.
        Since:
        1.5
      • setDate

        public HttpHeaders setDate​(java.lang.String date)
        Sets the "Date" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getETag

        public final java.lang.String getETag()
        Returns the first "ETag" header or null for none.
        Since:
        1.5
      • setETag

        public HttpHeaders setETag​(java.lang.String etag)
        Sets the "ETag" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getExpires

        public final java.lang.String getExpires()
        Returns the first "Expires" header or null for none.
        Since:
        1.5
      • setExpires

        public HttpHeaders setExpires​(java.lang.String expires)
        Sets the "Expires" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getIfModifiedSince

        public final java.lang.String getIfModifiedSince()
        Returns the first "If-Modified-Since" header or null for none.
        Since:
        1.5
      • setIfModifiedSince

        public HttpHeaders setIfModifiedSince​(java.lang.String ifModifiedSince)
        Sets the "If-Modified-Since" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getIfMatch

        public final java.lang.String getIfMatch()
        Returns the first "If-Match" header or null for none.
        Since:
        1.5
      • setIfMatch

        public HttpHeaders setIfMatch​(java.lang.String ifMatch)
        Sets the "If-Match" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getIfNoneMatch

        public final java.lang.String getIfNoneMatch()
        Returns the first "If-None-Match" header or null for none.
        Since:
        1.5
      • setIfNoneMatch

        public HttpHeaders setIfNoneMatch​(java.lang.String ifNoneMatch)
        Sets the "If-None-Match" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getIfUnmodifiedSince

        public final java.lang.String getIfUnmodifiedSince()
        Returns the first "If-Unmodified-Since" header or null for none.
        Since:
        1.5
      • setIfUnmodifiedSince

        public HttpHeaders setIfUnmodifiedSince​(java.lang.String ifUnmodifiedSince)
        Sets the "If-Unmodified-Since" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getIfRange

        public final java.lang.String getIfRange()
        Returns the first "If-Range" header or null for none.
        Since:
        1.14
      • setIfRange

        public HttpHeaders setIfRange​(java.lang.String ifRange)
        Sets the "If-Range" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.14
      • getLastModified

        public final java.lang.String getLastModified()
        Returns the first "Last-Modified" header or null for none.
        Since:
        1.5
      • setLastModified

        public HttpHeaders setLastModified​(java.lang.String lastModified)
        Sets the "Last-Modified" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getLocation

        public final java.lang.String getLocation()
        Returns the first "Location" header or null for none.
        Since:
        1.5
      • setLocation

        public HttpHeaders setLocation​(java.lang.String location)
        Sets the "Location" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getMimeVersion

        public final java.lang.String getMimeVersion()
        Returns the first "MIME-Version" header or null for none.
        Since:
        1.5
      • setMimeVersion

        public HttpHeaders setMimeVersion​(java.lang.String mimeVersion)
        Sets the "MIME-Version" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getRange

        public final java.lang.String getRange()
        Returns the first "Range" header or null for none.
        Since:
        1.5
      • setRange

        public HttpHeaders setRange​(java.lang.String range)
        Sets the "Range" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getRetryAfter

        public final java.lang.String getRetryAfter()
        Returns the first "Retry-After" header or null for none.
        Since:
        1.5
      • setRetryAfter

        public HttpHeaders setRetryAfter​(java.lang.String retryAfter)
        Sets the "Retry-After" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getUserAgent

        public final java.lang.String getUserAgent()
        Returns the first "User-Agent" header or null for none.
        Since:
        1.5
      • setUserAgent

        public HttpHeaders setUserAgent​(java.lang.String userAgent)
        Sets the "User-Agent" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • getAuthenticate

        public final java.lang.String getAuthenticate()
        Returns the first "WWW-Authenticate" header or null for none.
        Since:
        1.5
      • getAuthenticateAsList

        public final java.util.List<java.lang.String> getAuthenticateAsList()
        Returns all "WWW-Authenticate" headers or null for none.
        Since:
        1.16
      • setAuthenticate

        public HttpHeaders setAuthenticate​(java.lang.String authenticate)
        Sets the "WWW-Authenticate" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.5
      • addWarning

        public HttpHeaders addWarning​(java.lang.String warning)
        Adds the "Warning" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.28
      • getWarning

        public final java.util.List<java.lang.String> getWarning()
        Returns all "Warning" headers or null for none.
        Since:
        1.28
      • getAge

        public final java.lang.Long getAge()
        Returns the first "Age" header or null for none.
        Since:
        1.14
      • setAge

        public HttpHeaders setAge​(java.lang.Long age)
        Sets the "Age" header or null for none.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.14
      • setBasicAuthentication

        public HttpHeaders setBasicAuthentication​(java.lang.String username,
                                                  java.lang.String password)
        Sets the authorization header as specified in Basic Authentication Scheme.

        Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

        Since:
        1.2
      • addHeader

        private static void addHeader​(java.util.logging.Logger logger,
                                      java.lang.StringBuilder logbuf,
                                      java.lang.StringBuilder curlbuf,
                                      LowLevelHttpRequest lowLevelHttpRequest,
                                      java.lang.String name,
                                      java.lang.Object value,
                                      java.io.Writer writer)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • toStringValue

        private static java.lang.String toStringValue​(java.lang.Object headerValue)
        Returns the string header value for the given header value as an object.
      • serializeHeaders

        static void serializeHeaders​(HttpHeaders headers,
                                     java.lang.StringBuilder logbuf,
                                     java.lang.StringBuilder curlbuf,
                                     java.util.logging.Logger logger,
                                     LowLevelHttpRequest lowLevelHttpRequest)
                              throws java.io.IOException
        Serializes headers to an LowLevelHttpRequest.
        Parameters:
        headers - HTTP headers
        logbuf - log buffer or null for none
        curlbuf - log buffer for logging curl requests or null for none
        logger - logger or null for none. Logger must be specified if log buffer is specified
        lowLevelHttpRequest - low level HTTP request where HTTP headers will be serialized to or null for none
        Throws:
        java.io.IOException
      • serializeHeaders

        static void serializeHeaders​(HttpHeaders headers,
                                     java.lang.StringBuilder logbuf,
                                     java.lang.StringBuilder curlbuf,
                                     java.util.logging.Logger logger,
                                     LowLevelHttpRequest lowLevelHttpRequest,
                                     java.io.Writer writer)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • serializeHeadersForMultipartRequests

        public static void serializeHeadersForMultipartRequests​(HttpHeaders headers,
                                                                java.lang.StringBuilder logbuf,
                                                                java.util.logging.Logger logger,
                                                                java.io.Writer writer)
                                                         throws java.io.IOException
        Serializes headers to an Writer for Multi-part requests.
        Parameters:
        headers - HTTP headers
        logbuf - log buffer or null for none
        logger - logger or null for none. Logger must be specified if log buffer is specified
        writer - Writer where HTTP headers will be serialized to or null for none
        Throws:
        java.io.IOException
        Since:
        1.9
      • fromHttpResponse

        public final void fromHttpResponse​(LowLevelHttpResponse response,
                                           java.lang.StringBuilder logger)
                                    throws java.io.IOException
        Puts all headers of the LowLevelHttpResponse into this HttpHeaders object.
        Parameters:
        response - Response from which the headers are copied
        logger - StringBuilder to which logging output is added or null to disable logging
        Throws:
        java.io.IOException
        Since:
        1.10
      • getFirstHeaderValue

        private <T> T getFirstHeaderValue​(java.util.List<T> internalValue)
        Returns the first header value based on the given internal list value.
      • getAsList

        private <T> java.util.List<T> getAsList​(T passedValue)
        Returns the list value to use for the given parameter passed to the setter method.
      • getFirstHeaderStringValue

        public java.lang.String getFirstHeaderStringValue​(java.lang.String name)
        Returns the first header string value for the given header name.
        Parameters:
        name - header name (may be any case)
        Returns:
        first header string value or null if not found
        Since:
        1.13
      • getHeaderStringValues

        public java.util.List<java.lang.String> getHeaderStringValues​(java.lang.String name)
        Returns an unmodifiable list of the header string values for the given header name.
        Parameters:
        name - header name (may be any case)
        Returns:
        header string values or empty if not found
        Since:
        1.13
      • fromHttpHeaders

        public final void fromHttpHeaders​(HttpHeaders headers)
        Puts all headers of the HttpHeaders object into this HttpHeaders object.
        Parameters:
        headers - HttpHeaders from where the headers are taken
        Since:
        1.10
      • parseHeader

        void parseHeader​(java.lang.String headerName,
                         java.lang.String headerValue,
                         HttpHeaders.ParseHeaderState state)
        Parses the specified case-insensitive header pair into this HttpHeaders instance.
      • parseValue

        private static java.lang.Object parseValue​(java.lang.reflect.Type valueType,
                                                   java.util.List<java.lang.reflect.Type> context,
                                                   java.lang.String value)