org.springframework.http

Class HttpHeaders

  • java.lang.Object
    • org.springframework.http.HttpHeaders
  • All Implemented Interfaces:
    java.io.Serializable, java.util.Map<java.lang.String,java.util.List<java.lang.String>>, MultiValueMap<java.lang.String,java.lang.String>
    Direct Known Subclasses:
    WebSocketHttpHeaders


    public class HttpHeaders
    extends java.lang.Object
    implements MultiValueMap<java.lang.String,java.lang.String>, java.io.Serializable
    Represents HTTP request and response headers, mapping string header names to a list of string values.

    In addition to the normal methods defined by Map, this class offers the following convenience methods:

    Inspired by com.sun.net.httpserver.Headers.

    Since:
    3.0
    Author:
    Arjen Poutsma, Sebastien Deleuze, Brian Clozel, Juergen Hoeller, Josh Long
    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface java.util.Map

        java.util.Map.Entry<K,V>
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.lang.String ACCEPT
      The HTTP Accept header field name.
      static java.lang.String ACCEPT_CHARSET
      The HTTP Accept-Charset header field name.
      static java.lang.String ACCEPT_ENCODING
      The HTTP Accept-Encoding header field name.
      static java.lang.String ACCEPT_LANGUAGE
      The HTTP Accept-Language header field name.
      static java.lang.String ACCEPT_RANGES
      The HTTP Accept-Ranges header field name.
      static java.lang.String ACCESS_CONTROL_ALLOW_CREDENTIALS
      The CORS Access-Control-Allow-Credentials response header field name.
      static java.lang.String ACCESS_CONTROL_ALLOW_HEADERS
      The CORS Access-Control-Allow-Headers response header field name.
      static java.lang.String ACCESS_CONTROL_ALLOW_METHODS
      The CORS Access-Control-Allow-Methods response header field name.
      static java.lang.String ACCESS_CONTROL_ALLOW_ORIGIN
      The CORS Access-Control-Allow-Origin response header field name.
      static java.lang.String ACCESS_CONTROL_EXPOSE_HEADERS
      The CORS Access-Control-Expose-Headers response header field name.
      static java.lang.String ACCESS_CONTROL_MAX_AGE
      The CORS Access-Control-Max-Age response header field name.
      static java.lang.String ACCESS_CONTROL_REQUEST_HEADERS
      The CORS Access-Control-Request-Headers request header field name.
      static java.lang.String ACCESS_CONTROL_REQUEST_METHOD
      The CORS Access-Control-Request-Method request header field name.
      static java.lang.String AGE
      The HTTP Age header field name.
      static java.lang.String ALLOW
      The HTTP Allow header field name.
      static java.lang.String AUTHORIZATION
      The HTTP Authorization header field name.
      static java.lang.String CACHE_CONTROL
      The HTTP Cache-Control header field name.
      static java.lang.String CONNECTION
      The HTTP Connection header field name.
      static java.lang.String CONTENT_DISPOSITION
      The HTTP Content-Disposition header field name.
      static java.lang.String CONTENT_ENCODING
      The HTTP Content-Encoding header field name.
      static java.lang.String CONTENT_LANGUAGE
      The HTTP Content-Language header field name.
      static java.lang.String CONTENT_LENGTH
      The HTTP Content-Length header field name.
      static java.lang.String CONTENT_LOCATION
      The HTTP Content-Location header field name.
      static java.lang.String CONTENT_RANGE
      The HTTP Content-Range header field name.
      static java.lang.String CONTENT_TYPE
      The HTTP Content-Type header field name.
      static java.lang.String COOKIE
      The HTTP Cookie header field name.
      static java.lang.String DATE
      The HTTP Date header field name.
      static HttpHeaders EMPTY
      The empty HttpHeaders instance (immutable).
      static java.lang.String ETAG
      The HTTP ETag header field name.
      static java.lang.String EXPECT
      The HTTP Expect header field name.
      static java.lang.String EXPIRES
      The HTTP Expires header field name.
      static java.lang.String FROM
      The HTTP From header field name.
      static java.lang.String HOST
      The HTTP Host header field name.
      static java.lang.String IF_MATCH
      The HTTP If-Match header field name.
      static java.lang.String IF_MODIFIED_SINCE
      The HTTP If-Modified-Since header field name.
      static java.lang.String IF_NONE_MATCH
      The HTTP If-None-Match header field name.
      static java.lang.String IF_RANGE
      The HTTP If-Range header field name.
      static java.lang.String IF_UNMODIFIED_SINCE
      The HTTP If-Unmodified-Since header field name.
      static java.lang.String LAST_MODIFIED
      The HTTP Last-Modified header field name.
      static java.lang.String LINK
      The HTTP Link header field name.
      static java.lang.String LOCATION
      The HTTP Location header field name.
      static java.lang.String MAX_FORWARDS
      The HTTP Max-Forwards header field name.
      static java.lang.String ORIGIN
      The HTTP Origin header field name.
      static java.lang.String PRAGMA
      The HTTP Pragma header field name.
      static java.lang.String PROXY_AUTHENTICATE
      The HTTP Proxy-Authenticate header field name.
      static java.lang.String PROXY_AUTHORIZATION
      The HTTP Proxy-Authorization header field name.
      static java.lang.String RANGE
      The HTTP Range header field name.
      static java.lang.String REFERER
      The HTTP Referer header field name.
      static java.lang.String RETRY_AFTER
      The HTTP Retry-After header field name.
      static java.lang.String SERVER
      The HTTP Server header field name.
      static java.lang.String SET_COOKIE
      The HTTP Set-Cookie header field name.
      static java.lang.String SET_COOKIE2
      The HTTP Set-Cookie2 header field name.
      static java.lang.String TE
      The HTTP TE header field name.
      static java.lang.String TRAILER
      The HTTP Trailer header field name.
      static java.lang.String TRANSFER_ENCODING
      The HTTP Transfer-Encoding header field name.
      static java.lang.String UPGRADE
      The HTTP Upgrade header field name.
      static java.lang.String USER_AGENT
      The HTTP User-Agent header field name.
      static java.lang.String VARY
      The HTTP Vary header field name.
      static java.lang.String VIA
      The HTTP Via header field name.
      static java.lang.String WARNING
      The HTTP Warning header field name.
      static java.lang.String WWW_AUTHENTICATE
      The HTTP WWW-Authenticate header field name.
    • Constructor Summary

      Constructors 
      Constructor and Description
      HttpHeaders()
      Constructs a new, empty instance of the HttpHeaders object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void add(java.lang.String headerName, java.lang.String headerValue)
      Add the given, single header value under the given name.
      void addAll(MultiValueMap<java.lang.String,java.lang.String> values)
      Add all the values of the given MultiValueMap to the current values.
      void addAll(java.lang.String key, java.util.List<? extends java.lang.String> values)
      Add all the values of the given list to the current list of values for the given key.
      void clear() 
      boolean containsKey(java.lang.Object key) 
      boolean containsValue(java.lang.Object value) 
      java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> entrySet() 
      boolean equals(java.lang.Object other) 
      java.util.List<java.lang.String> get(java.lang.Object key) 
      java.util.List<MediaType> getAccept()
      Return the list of acceptable media types, as specified by the Accept header.
      java.util.List<java.nio.charset.Charset> getAcceptCharset()
      Return the list of acceptable charsets, as specified by the Accept-Charset header.
      java.util.List<java.util.Locale.LanguageRange> getAcceptLanguage()
      Return the language ranges from the "Accept-Language" header.
      java.util.List<java.util.Locale> getAcceptLanguageAsLocales()
      A variant of getAcceptLanguage() that converts each Locale.LanguageRange to a Locale.
      boolean getAccessControlAllowCredentials()
      Return the value of the Access-Control-Allow-Credentials response header.
      java.util.List<java.lang.String> getAccessControlAllowHeaders()
      Return the value of the Access-Control-Allow-Headers response header.
      java.util.List<HttpMethod> getAccessControlAllowMethods()
      Return the value of the Access-Control-Allow-Methods response header.
      java.lang.String getAccessControlAllowOrigin()
      Return the value of the Access-Control-Allow-Origin response header.
      java.util.List<java.lang.String> getAccessControlExposeHeaders()
      Return the value of the Access-Control-Expose-Headers response header.
      long getAccessControlMaxAge()
      Return the value of the Access-Control-Max-Age response header.
      java.util.List<java.lang.String> getAccessControlRequestHeaders()
      Return the value of the Access-Control-Request-Headers request header.
      HttpMethod getAccessControlRequestMethod()
      Return the value of the Access-Control-Request-Method request header.
      java.util.Set<HttpMethod> getAllow()
      Return the set of allowed HTTP methods, as specified by the Allow header.
      java.lang.String getCacheControl()
      Return the value of the Cache-Control header.
      java.util.List<java.lang.String> getConnection()
      Return the value of the Connection header.
      ContentDisposition getContentDisposition()
      Return a parsed representation of the Content-Disposition header.
      java.util.Locale getContentLanguage()
      Return the first Locale of the content languages, as specified by the Content-Language header.
      long getContentLength()
      Return the length of the body in bytes, as specified by the Content-Length header.
      MediaType getContentType()
      Return the media type of the body, as specified by the Content-Type header.
      long getDate()
      Return the date and time at which the message was created, as specified by the Date header.
      java.lang.String getETag()
      Return the entity tag of the body, as specified by the ETag header.
      protected java.util.List<java.lang.String> getETagValuesAsList(java.lang.String headerName)
      Retrieve a combined result from the field values of the ETag header.
      long getExpires()
      Return the date and time at which the message is no longer valid, as specified by the Expires header.
      protected java.lang.String getFieldValues(java.lang.String headerName)
      Retrieve a combined result from the field values of multi-valued headers.
      java.lang.String getFirst(java.lang.String headerName)
      Return the first header value for the given header name, if any.
      long getFirstDate(java.lang.String headerName)
      Parse the first header value for the given header name as a date, return -1 if there is no value, or raise IllegalArgumentException if the value cannot be parsed as a date.
      java.time.ZonedDateTime getFirstZonedDateTime(java.lang.String headerName)
      Parse the first header value for the given header name as a date, return null if there is no value, or raise IllegalArgumentException if the value cannot be parsed as a date.
      java.net.InetSocketAddress getHost()
      Return the value of the required Host header.
      java.util.List<java.lang.String> getIfMatch()
      Return the value of the If-Match header.
      long getIfModifiedSince()
      Return the value of the If-Modified-Since header.
      java.util.List<java.lang.String> getIfNoneMatch()
      Return the value of the If-None-Match header.
      long getIfUnmodifiedSince()
      Return the value of the If-Unmodified-Since header.
      long getLastModified()
      Return the time the resource was last changed, as specified by the Last-Modified header.
      java.net.URI getLocation()
      Return the (new) location of a resource as specified by the Location header.
      java.lang.String getOrigin()
      Return the value of the Origin header.
      java.lang.String getPragma()
      Return the value of the Pragma header.
      java.util.List<HttpRange> getRange()
      Return the value of the Range header.
      java.lang.String getUpgrade()
      Return the value of the Upgrade header.
      java.util.List<java.lang.String> getValuesAsList(java.lang.String headerName)
      Return all values of a given header name, even if this header is set multiple times.
      java.util.List<java.lang.String> getVary()
      Return the request header names subject to content negotiation.
      int hashCode() 
      boolean isEmpty() 
      java.util.Set<java.lang.String> keySet() 
      java.util.List<java.lang.String> put(java.lang.String key, java.util.List<java.lang.String> value) 
      void putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> map) 
      static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
      Return a HttpHeaders object that can only be read, not written to.
      java.util.List<java.lang.String> remove(java.lang.Object key) 
      void set(java.lang.String headerName, java.lang.String headerValue)
      Set the given, single header value under the given name.
      void setAccept(java.util.List<MediaType> acceptableMediaTypes)
      Set the list of acceptable media types, as specified by the Accept header.
      void setAcceptCharset(java.util.List<java.nio.charset.Charset> acceptableCharsets)
      Set the list of acceptable charsets, as specified by the Accept-Charset header.
      void setAcceptLanguage(java.util.List<java.util.Locale.LanguageRange> languages)
      Set the acceptable language ranges, as specified by the Accept-Language header.
      void setAcceptLanguageAsLocales(java.util.List<java.util.Locale> locales)
      Variant of setAcceptLanguage(List) using Locale's.
      void setAccessControlAllowCredentials(boolean allowCredentials)
      Set the (new) value of the Access-Control-Allow-Credentials response header.
      void setAccessControlAllowHeaders(java.util.List<java.lang.String> allowedHeaders)
      Set the (new) value of the Access-Control-Allow-Headers response header.
      void setAccessControlAllowMethods(java.util.List<HttpMethod> allowedMethods)
      Set the (new) value of the Access-Control-Allow-Methods response header.
      void setAccessControlAllowOrigin(java.lang.String allowedOrigin)
      Set the (new) value of the Access-Control-Allow-Origin response header.
      void setAccessControlExposeHeaders(java.util.List<java.lang.String> exposedHeaders)
      Set the (new) value of the Access-Control-Expose-Headers response header.
      void setAccessControlMaxAge(long maxAge)
      Set the (new) value of the Access-Control-Max-Age response header.
      void setAccessControlRequestHeaders(java.util.List<java.lang.String> requestHeaders)
      Set the (new) value of the Access-Control-Request-Headers request header.
      void setAccessControlRequestMethod(HttpMethod requestMethod)
      Set the (new) value of the Access-Control-Request-Method request header.
      void setAll(java.util.Map<java.lang.String,java.lang.String> values)
      Set the given values under.
      void setAllow(java.util.Set<HttpMethod> allowedMethods)
      Set the set of allowed HTTP methods, as specified by the Allow header.
      void setBasicAuth(java.lang.String username, java.lang.String password)
      Set the value of the Authorization header to Basic Authentication based on the given username and password.
      void setBasicAuth(java.lang.String username, java.lang.String password, java.nio.charset.Charset charset)
      Set the value of the Authorization header to Basic Authentication based on the given username and password.
      void setBearerAuth(java.lang.String token)
      Set the value of the Authorization header to the given Bearer token.
      void setCacheControl(CacheControl cacheControl)
      Set a configured CacheControl instance as the new value of the Cache-Control header.
      void setCacheControl(java.lang.String cacheControl)
      Set the (new) value of the Cache-Control header.
      void setConnection(java.util.List<java.lang.String> connection)
      Set the (new) value of the Connection header.
      void setConnection(java.lang.String connection)
      Set the (new) value of the Connection header.
      void setContentDisposition(ContentDisposition contentDisposition)
      Set the Content-Disposition header.
      void setContentDispositionFormData(java.lang.String name, java.lang.String filename)
      Set the Content-Disposition header when creating a "multipart/form-data" request.
      void setContentLanguage(java.util.Locale locale)
      Set the Locale of the content language, as specified by the Content-Language header.
      void setContentLength(long contentLength)
      Set the length of the body in bytes, as specified by the Content-Length header.
      void setContentType(MediaType mediaType)
      Set the media type of the body, as specified by the Content-Type header.
      void setDate(long date)
      Set the date and time at which the message was created, as specified by the Date header.
      void setDate(java.lang.String headerName, long date)
      Set the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter.
      void setETag(java.lang.String etag)
      Set the (new) entity tag of the body, as specified by the ETag header.
      void setExpires(long expires)
      Set the date and time at which the message is no longer valid, as specified by the Expires header.
      void setExpires(java.time.ZonedDateTime expires)
      Set the duration after which the message is no longer valid, as specified by the Expires header.
      void setHost(java.net.InetSocketAddress host)
      Set the (new) value of the Host header.
      void setIfMatch(java.util.List<java.lang.String> ifMatchList)
      Set the (new) value of the If-Match header.
      void setIfMatch(java.lang.String ifMatch)
      Set the (new) value of the If-Match header.
      void setIfModifiedSince(long ifModifiedSince)
      Set the (new) value of the If-Modified-Since header.
      void setIfNoneMatch(java.util.List<java.lang.String> ifNoneMatchList)
      Set the (new) values of the If-None-Match header.
      void setIfNoneMatch(java.lang.String ifNoneMatch)
      Set the (new) value of the If-None-Match header.
      void setIfUnmodifiedSince(long ifUnmodifiedSince)
      Set the (new) value of the If-Unmodified-Since header.
      void setLastModified(long lastModified)
      Set the time the resource was last changed, as specified by the Last-Modified header.
      void setLocation(java.net.URI location)
      Set the (new) location of a resource, as specified by the Location header.
      void setOrigin(java.lang.String origin)
      Set the (new) value of the Origin header.
      void setPragma(java.lang.String pragma)
      Set the (new) value of the Pragma header.
      void setRange(java.util.List<HttpRange> ranges)
      Sets the (new) value of the Range header.
      void setUpgrade(java.lang.String upgrade)
      Set the (new) value of the Upgrade header.
      void setVary(java.util.List<java.lang.String> requestHeaders)
      Set the request header names (e.g.
      void setZonedDateTime(java.lang.String headerName, java.time.ZonedDateTime date)
      Set the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter.
      int size() 
      protected java.lang.String toCommaDelimitedString(java.util.List<java.lang.String> headerValues)
      Turn the given list of header values into a comma-delimited result.
      java.util.Map<java.lang.String,java.lang.String> toSingleValueMap()
      Returns the first values contained in this MultiValueMap.
      java.lang.String toString() 
      java.util.Collection<java.util.List<java.lang.String>> values() 
      • Methods inherited from class java.lang.Object

        clone, 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
    • Constructor Detail

      • HttpHeaders

        public HttpHeaders()
        Constructs a new, empty instance of the HttpHeaders object.
    • Method Detail

      • setAccept

        public void setAccept(java.util.List<MediaType> acceptableMediaTypes)
        Set the list of acceptable media types, as specified by the Accept header.
      • getAccept

        public java.util.List<MediaType> getAccept()
        Return the list of acceptable media types, as specified by the Accept header.

        Returns an empty list when the acceptable media types are unspecified.

      • setAcceptLanguage

        public void setAcceptLanguage(java.util.List<java.util.Locale.LanguageRange> languages)
        Set the acceptable language ranges, as specified by the Accept-Language header.
        Since:
        5.0
      • getAcceptLanguage

        public java.util.List<java.util.Locale.LanguageRange> getAcceptLanguage()
        Return the language ranges from the "Accept-Language" header.

        If you only need sorted, preferred locales only use getAcceptLanguageAsLocales() or if you need to filter based on a list of supported locales you can pass the returned list to Locale.filter(List, Collection).

        Throws:
        java.lang.IllegalArgumentException - if the value cannot be converted to a language range
        Since:
        5.0
      • setAcceptLanguageAsLocales

        public void setAcceptLanguageAsLocales(java.util.List<java.util.Locale> locales)
        Variant of setAcceptLanguage(List) using Locale's.
        Since:
        5.0
      • getAcceptLanguageAsLocales

        public java.util.List<java.util.Locale> getAcceptLanguageAsLocales()
        A variant of getAcceptLanguage() that converts each Locale.LanguageRange to a Locale.
        Returns:
        the locales or an empty list
        Throws:
        java.lang.IllegalArgumentException - if the value cannot be converted to a locale
        Since:
        5.0
      • setAccessControlAllowCredentials

        public void setAccessControlAllowCredentials(boolean allowCredentials)
        Set the (new) value of the Access-Control-Allow-Credentials response header.
      • getAccessControlAllowCredentials

        public boolean getAccessControlAllowCredentials()
        Return the value of the Access-Control-Allow-Credentials response header.
      • setAccessControlAllowHeaders

        public void setAccessControlAllowHeaders(java.util.List<java.lang.String> allowedHeaders)
        Set the (new) value of the Access-Control-Allow-Headers response header.
      • getAccessControlAllowHeaders

        public java.util.List<java.lang.String> getAccessControlAllowHeaders()
        Return the value of the Access-Control-Allow-Headers response header.
      • setAccessControlAllowMethods

        public void setAccessControlAllowMethods(java.util.List<HttpMethod> allowedMethods)
        Set the (new) value of the Access-Control-Allow-Methods response header.
      • getAccessControlAllowMethods

        public java.util.List<HttpMethod> getAccessControlAllowMethods()
        Return the value of the Access-Control-Allow-Methods response header.
      • setAccessControlAllowOrigin

        public void setAccessControlAllowOrigin(@Nullable
                                                java.lang.String allowedOrigin)
        Set the (new) value of the Access-Control-Allow-Origin response header.
      • getAccessControlAllowOrigin

        @Nullable
        public java.lang.String getAccessControlAllowOrigin()
        Return the value of the Access-Control-Allow-Origin response header.
      • setAccessControlExposeHeaders

        public void setAccessControlExposeHeaders(java.util.List<java.lang.String> exposedHeaders)
        Set the (new) value of the Access-Control-Expose-Headers response header.
      • getAccessControlExposeHeaders

        public java.util.List<java.lang.String> getAccessControlExposeHeaders()
        Return the value of the Access-Control-Expose-Headers response header.
      • setAccessControlMaxAge

        public void setAccessControlMaxAge(long maxAge)
        Set the (new) value of the Access-Control-Max-Age response header.
      • getAccessControlMaxAge

        public long getAccessControlMaxAge()
        Return the value of the Access-Control-Max-Age response header.

        Returns -1 when the max age is unknown.

      • setAccessControlRequestHeaders

        public void setAccessControlRequestHeaders(java.util.List<java.lang.String> requestHeaders)
        Set the (new) value of the Access-Control-Request-Headers request header.
      • getAccessControlRequestHeaders

        public java.util.List<java.lang.String> getAccessControlRequestHeaders()
        Return the value of the Access-Control-Request-Headers request header.
      • setAccessControlRequestMethod

        public void setAccessControlRequestMethod(@Nullable
                                                  HttpMethod requestMethod)
        Set the (new) value of the Access-Control-Request-Method request header.
      • getAccessControlRequestMethod

        @Nullable
        public HttpMethod getAccessControlRequestMethod()
        Return the value of the Access-Control-Request-Method request header.
      • setAcceptCharset

        public void setAcceptCharset(java.util.List<java.nio.charset.Charset> acceptableCharsets)
        Set the list of acceptable charsets, as specified by the Accept-Charset header.
      • getAcceptCharset

        public java.util.List<java.nio.charset.Charset> getAcceptCharset()
        Return the list of acceptable charsets, as specified by the Accept-Charset header.
      • setAllow

        public void setAllow(java.util.Set<HttpMethod> allowedMethods)
        Set the set of allowed HTTP methods, as specified by the Allow header.
      • getAllow

        public java.util.Set<HttpMethod> getAllow()
        Return the set of allowed HTTP methods, as specified by the Allow header.

        Returns an empty set when the allowed methods are unspecified.

      • setBasicAuth

        public void setBasicAuth(java.lang.String username,
                                 java.lang.String password)
        Set the value of the Authorization header to Basic Authentication based on the given username and password.

        Note that Basic Authentication only supports characters in the ISO-8859-1 character set.

        Parameters:
        username - the username
        password - the password
        Throws:
        java.lang.IllegalArgumentException - if either user or password contain characters that cannot be encoded to ISO-8859-1.
        Since:
        5.1
        See Also:
        RFC 7617
      • setBasicAuth

        public void setBasicAuth(java.lang.String username,
                                 java.lang.String password,
                                 @Nullable
                                 java.nio.charset.Charset charset)
        Set the value of the Authorization header to Basic Authentication based on the given username and password.
        Parameters:
        username - the username
        password - the password
        charset - the charset to use to convert the credentials into an octet sequence. Defaults to ISO-8859-1
        Throws:
        java.lang.IllegalArgumentException - if either user or password contain characters that cannot be encoded to ISO-8859-1.
        Since:
        5.1
        See Also:
        RFC 7617
      • setBearerAuth

        public void setBearerAuth(java.lang.String token)
        Set the value of the Authorization header to the given Bearer token.
        Parameters:
        token - the Base64 encoded token
        Since:
        5.1
        See Also:
        RFC 6750
      • setCacheControl

        public void setCacheControl(CacheControl cacheControl)
        Set a configured CacheControl instance as the new value of the Cache-Control header.
        Since:
        5.0.5
      • setCacheControl

        public void setCacheControl(@Nullable
                                    java.lang.String cacheControl)
        Set the (new) value of the Cache-Control header.
      • getCacheControl

        @Nullable
        public java.lang.String getCacheControl()
        Return the value of the Cache-Control header.
      • setConnection

        public void setConnection(java.lang.String connection)
        Set the (new) value of the Connection header.
      • setConnection

        public void setConnection(java.util.List<java.lang.String> connection)
        Set the (new) value of the Connection header.
      • getConnection

        public java.util.List<java.lang.String> getConnection()
        Return the value of the Connection header.
      • setContentDispositionFormData

        public void setContentDispositionFormData(java.lang.String name,
                                                  @Nullable
                                                  java.lang.String filename)
        Set the Content-Disposition header when creating a "multipart/form-data" request.

        Applications typically would not set this header directly but rather prepare a MultiValueMap<String, Object>, containing an Object or a Resource for each part, and then pass that to the RestTemplate or WebClient.

        Parameters:
        name - the control name
        filename - the filename (may be null)
        See Also:
        getContentDisposition()
      • setContentLanguage

        public void setContentLanguage(@Nullable
                                       java.util.Locale locale)
        Set the Locale of the content language, as specified by the Content-Language header.

        Use set(CONTENT_LANGUAGE, ...) if you need to set multiple content languages.

        Since:
        5.0
      • getContentLanguage

        @Nullable
        public java.util.Locale getContentLanguage()
        Return the first Locale of the content languages, as specified by the Content-Language header.

        Returns null when the content language is unknown.

        Use getValuesAsList(CONTENT_LANGUAGE) if you need to get multiple content languages.

        Since:
        5.0
      • setContentLength

        public void setContentLength(long contentLength)
        Set the length of the body in bytes, as specified by the Content-Length header.
      • getContentLength

        public long getContentLength()
        Return the length of the body in bytes, as specified by the Content-Length header.

        Returns -1 when the content-length is unknown.

      • setContentType

        public void setContentType(@Nullable
                                   MediaType mediaType)
        Set the media type of the body, as specified by the Content-Type header.
      • getContentType

        @Nullable
        public MediaType getContentType()
        Return the media type of the body, as specified by the Content-Type header.

        Returns null when the content-type is unknown.

      • setDate

        public void setDate(long date)
        Set the date and time at which the message was created, as specified by the Date header.

        The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      • getDate

        public long getDate()
        Return the date and time at which the message was created, as specified by the Date header.

        The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

        Throws:
        java.lang.IllegalArgumentException - if the value cannot be converted to a date
      • setETag

        public void setETag(@Nullable
                            java.lang.String etag)
        Set the (new) entity tag of the body, as specified by the ETag header.
      • getETag

        @Nullable
        public java.lang.String getETag()
        Return the entity tag of the body, as specified by the ETag header.
      • setExpires

        public void setExpires(java.time.ZonedDateTime expires)
        Set the duration after which the message is no longer valid, as specified by the Expires header.
        Since:
        5.0.5
      • setExpires

        public void setExpires(long expires)
        Set the date and time at which the message is no longer valid, as specified by the Expires header.

        The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      • getExpires

        public long getExpires()
        Return the date and time at which the message is no longer valid, as specified by the Expires header.

        The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

        See Also:
        getFirstZonedDateTime(String)
      • setHost

        public void setHost(@Nullable
                            java.net.InetSocketAddress host)
        Set the (new) value of the Host header.

        If the given port is 0, the host header will only contain the host name.

        Since:
        5.0
      • getHost

        @Nullable
        public java.net.InetSocketAddress getHost()
        Return the value of the required Host header.

        If the header value does not contain a port, the returned port will be 0.

        Since:
        5.0
      • setIfMatch

        public void setIfMatch(java.lang.String ifMatch)
        Set the (new) value of the If-Match header.
        Since:
        4.3
      • setIfMatch

        public void setIfMatch(java.util.List<java.lang.String> ifMatchList)
        Set the (new) value of the If-Match header.
        Since:
        4.3
      • getIfMatch

        public java.util.List<java.lang.String> getIfMatch()
        Return the value of the If-Match header.
        Since:
        4.3
      • setIfModifiedSince

        public void setIfModifiedSince(long ifModifiedSince)
        Set the (new) value of the If-Modified-Since header.

        The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      • getIfModifiedSince

        public long getIfModifiedSince()
        Return the value of the If-Modified-Since header.

        The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

        See Also:
        getFirstZonedDateTime(String)
      • setIfNoneMatch

        public void setIfNoneMatch(java.lang.String ifNoneMatch)
        Set the (new) value of the If-None-Match header.
      • setIfNoneMatch

        public void setIfNoneMatch(java.util.List<java.lang.String> ifNoneMatchList)
        Set the (new) values of the If-None-Match header.
      • getIfNoneMatch

        public java.util.List<java.lang.String> getIfNoneMatch()
        Return the value of the If-None-Match header.
      • setIfUnmodifiedSince

        public void setIfUnmodifiedSince(long ifUnmodifiedSince)
        Set the (new) value of the If-Unmodified-Since header.

        The date should be specified as the number of milliseconds since January 1, 1970 GMT.

        Since:
        4.3
      • getIfUnmodifiedSince

        public long getIfUnmodifiedSince()
        Return the value of the If-Unmodified-Since header.

        The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

        Since:
        4.3
        See Also:
        getFirstZonedDateTime(String)
      • setLastModified

        public void setLastModified(long lastModified)
        Set the time the resource was last changed, as specified by the Last-Modified header.

        The date should be specified as the number of milliseconds since January 1, 1970 GMT.

      • getLastModified

        public long getLastModified()
        Return the time the resource was last changed, as specified by the Last-Modified header.

        The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.

        See Also:
        getFirstZonedDateTime(String)
      • setLocation

        public void setLocation(@Nullable
                                java.net.URI location)
        Set the (new) location of a resource, as specified by the Location header.
      • getLocation

        @Nullable
        public java.net.URI getLocation()
        Return the (new) location of a resource as specified by the Location header.

        Returns null when the location is unknown.

      • setOrigin

        public void setOrigin(@Nullable
                              java.lang.String origin)
        Set the (new) value of the Origin header.
      • getOrigin

        @Nullable
        public java.lang.String getOrigin()
        Return the value of the Origin header.
      • setPragma

        public void setPragma(@Nullable
                              java.lang.String pragma)
        Set the (new) value of the Pragma header.
      • getPragma

        @Nullable
        public java.lang.String getPragma()
        Return the value of the Pragma header.
      • setRange

        public void setRange(java.util.List<HttpRange> ranges)
        Sets the (new) value of the Range header.
      • getRange

        public java.util.List<HttpRange> getRange()
        Return the value of the Range header.

        Returns an empty list when the range is unknown.

      • setUpgrade

        public void setUpgrade(@Nullable
                               java.lang.String upgrade)
        Set the (new) value of the Upgrade header.
      • getUpgrade

        @Nullable
        public java.lang.String getUpgrade()
        Return the value of the Upgrade header.
      • setVary

        public void setVary(java.util.List<java.lang.String> requestHeaders)
        Set the request header names (e.g. "Accept-Language") for which the response is subject to content negotiation and variances based on the value of those request headers.
        Parameters:
        requestHeaders - the request header names
        Since:
        4.3
      • getVary

        public java.util.List<java.lang.String> getVary()
        Return the request header names subject to content negotiation.
        Since:
        4.3
      • setZonedDateTime

        public void setZonedDateTime(java.lang.String headerName,
                                     java.time.ZonedDateTime date)
        Set the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter. The equivalent of set(String, String) but for date headers.
        Since:
        5.0
      • setDate

        public void setDate(java.lang.String headerName,
                            long date)
        Set the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter. The equivalent of set(String, String) but for date headers.
        Since:
        3.2.4
        See Also:
        setZonedDateTime(String, ZonedDateTime)
      • getFirstDate

        public long getFirstDate(java.lang.String headerName)
        Parse the first header value for the given header name as a date, return -1 if there is no value, or raise IllegalArgumentException if the value cannot be parsed as a date.
        Parameters:
        headerName - the header name
        Returns:
        the parsed date header, or -1 if none
        Since:
        3.2.4
        See Also:
        getFirstZonedDateTime(String)
      • getFirstZonedDateTime

        @Nullable
        public java.time.ZonedDateTime getFirstZonedDateTime(java.lang.String headerName)
        Parse the first header value for the given header name as a date, return null if there is no value, or raise IllegalArgumentException if the value cannot be parsed as a date.
        Parameters:
        headerName - the header name
        Returns:
        the parsed date header, or null if none
        Since:
        5.0
      • getValuesAsList

        public java.util.List<java.lang.String> getValuesAsList(java.lang.String headerName)
        Return all values of a given header name, even if this header is set multiple times.
        Parameters:
        headerName - the header name
        Returns:
        all associated values
        Since:
        4.3
      • getETagValuesAsList

        protected java.util.List<java.lang.String> getETagValuesAsList(java.lang.String headerName)
        Retrieve a combined result from the field values of the ETag header.
        Parameters:
        headerName - the header name
        Returns:
        the combined result
        Since:
        4.3
      • getFieldValues

        @Nullable
        protected java.lang.String getFieldValues(java.lang.String headerName)
        Retrieve a combined result from the field values of multi-valued headers.
        Parameters:
        headerName - the header name
        Returns:
        the combined result
        Since:
        4.3
      • toCommaDelimitedString

        protected java.lang.String toCommaDelimitedString(java.util.List<java.lang.String> headerValues)
        Turn the given list of header values into a comma-delimited result.
        Parameters:
        headerValues - the list of header values
        Returns:
        a combined result with comma delimitation
      • getFirst

        @Nullable
        public java.lang.String getFirst(java.lang.String headerName)
        Return the first header value for the given header name, if any.
        Specified by:
        getFirst in interface MultiValueMap<java.lang.String,java.lang.String>
        Parameters:
        headerName - the header name
        Returns:
        the first header value, or null if none
      • add

        public void add(java.lang.String headerName,
                        @Nullable
                        java.lang.String headerValue)
        Add the given, single header value under the given name.
        Specified by:
        add in interface MultiValueMap<java.lang.String,java.lang.String>
        Parameters:
        headerName - the header name
        headerValue - the header value
        Throws:
        java.lang.UnsupportedOperationException - if adding headers is not supported
        See Also:
        put(String, List), set(String, String)
      • addAll

        public void addAll(java.lang.String key,
                           java.util.List<? extends java.lang.String> values)
        Description copied from interface: MultiValueMap
        Add all the values of the given list to the current list of values for the given key.
        Specified by:
        addAll in interface MultiValueMap<java.lang.String,java.lang.String>
        Parameters:
        key - they key
        values - the values to be added
      • addAll

        public void addAll(MultiValueMap<java.lang.String,java.lang.String> values)
        Description copied from interface: MultiValueMap
        Add all the values of the given MultiValueMap to the current values.
        Specified by:
        addAll in interface MultiValueMap<java.lang.String,java.lang.String>
        Parameters:
        values - the values to be added
      • set

        public void set(java.lang.String headerName,
                        @Nullable
                        java.lang.String headerValue)
        Set the given, single header value under the given name.
        Specified by:
        set in interface MultiValueMap<java.lang.String,java.lang.String>
        Parameters:
        headerName - the header name
        headerValue - the header value
        Throws:
        java.lang.UnsupportedOperationException - if adding headers is not supported
        See Also:
        put(String, List), add(String, String)
      • setAll

        public void setAll(java.util.Map<java.lang.String,java.lang.String> values)
        Description copied from interface: MultiValueMap
        Set the given values under.
        Specified by:
        setAll in interface MultiValueMap<java.lang.String,java.lang.String>
        Parameters:
        values - the values.
      • toSingleValueMap

        public java.util.Map<java.lang.String,java.lang.String> toSingleValueMap()
        Description copied from interface: MultiValueMap
        Returns the first values contained in this MultiValueMap.
        Specified by:
        toSingleValueMap in interface MultiValueMap<java.lang.String,java.lang.String>
        Returns:
        a single value representation of this map
      • size

        public int size()
        Specified by:
        size in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • containsKey

        public boolean containsKey(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • containsValue

        public boolean containsValue(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • get

        @Nullable
        public java.util.List<java.lang.String> get(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • put

        public java.util.List<java.lang.String> put(java.lang.String key,
                                                    java.util.List<java.lang.String> value)
        Specified by:
        put in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • remove

        public java.util.List<java.lang.String> remove(java.lang.Object key)
        Specified by:
        remove in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • putAll

        public void putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> map)
        Specified by:
        putAll in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • keySet

        public java.util.Set<java.lang.String> keySet()
        Specified by:
        keySet in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • values

        public java.util.Collection<java.util.List<java.lang.String>> values()
        Specified by:
        values in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • entrySet

        public java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
      • equals

        public boolean equals(java.lang.Object other)
        Specified by:
        equals in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>
        Overrides:
        hashCode in class java.lang.Object
      • toString

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

        public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
        Return a HttpHeaders object that can only be read, not written to.