Class HttpHeaders
- All Implemented Interfaces:
- Serializable,- Map<String,,- List<String>> - MultiValueMap<String,- String> 
- Direct Known Subclasses:
- WebSocketHttpHeaders
In addition to the regular methods defined by Map, this class offers many common
 convenience methods, for example:
 
- getFirst(String)returns the first value associated with a given header name
- add(String, String)adds a header value to the list of values for a header name
- set(String, String)sets the header value to a single string value
Note that HttpHeaders generally treats header names in a case-insensitive manner.
- Since:
- 3.0
- Author:
- Arjen Poutsma, Sebastien Deleuze, Brian Clozel, Juergen Hoeller, Josh Long, Sam Brannen
- See Also:
- 
Nested Class Summary
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringThe HTTPAcceptheader field name.static final StringThe HTTPAccept-Charsetheader field name.static final StringThe HTTPAccept-Encodingheader field name.static final StringThe HTTPAccept-Languageheader field name.static final StringThe HTTPAccept-Patchheader field name.static final StringThe HTTPAccept-Rangesheader field name.static final StringThe CORSAccess-Control-Allow-Credentialsresponse header field name.static final StringThe CORSAccess-Control-Allow-Headersresponse header field name.static final StringThe CORSAccess-Control-Allow-Methodsresponse header field name.static final StringThe CORSAccess-Control-Allow-Originresponse header field name.static final StringThe CORSAccess-Control-Expose-Headersresponse header field name.static final StringThe CORSAccess-Control-Max-Ageresponse header field name.static final StringThe CORSAccess-Control-Request-Headersrequest header field name.static final StringThe CORSAccess-Control-Request-Methodrequest header field name.static final StringThe HTTPAgeheader field name.static final StringThe HTTPAllowheader field name.static final StringThe HTTPAuthorizationheader field name.static final StringThe HTTPCache-Controlheader field name.static final StringThe HTTPConnectionheader field name.static final StringThe HTTPContent-Dispositionheader field name.static final StringThe HTTPContent-Encodingheader field name.static final StringThe HTTPContent-Languageheader field name.static final StringThe HTTPContent-Lengthheader field name.static final StringThe HTTPContent-Locationheader field name.static final StringThe HTTPContent-Rangeheader field name.static final StringThe HTTPContent-Typeheader field name.static final StringThe HTTPCookieheader field name.static final StringThe HTTPDateheader field name.static final HttpHeadersAn emptyHttpHeadersinstance (immutable).static final StringThe HTTPETagheader field name.static final StringThe HTTPExpectheader field name.static final StringThe HTTPExpiresheader field name.static final StringThe HTTPFromheader field name.static final StringThe HTTPHostheader field name.static final StringThe HTTPIf-Matchheader field name.static final StringThe HTTPIf-Modified-Sinceheader field name.static final StringThe HTTPIf-None-Matchheader field name.static final StringThe HTTPIf-Rangeheader field name.static final StringThe HTTPIf-Unmodified-Sinceheader field name.static final StringThe HTTPLast-Modifiedheader field name.static final StringThe HTTPLinkheader field name.static final StringThe HTTPLocationheader field name.static final StringThe HTTPMax-Forwardsheader field name.static final StringThe HTTPOriginheader field name.static final StringThe HTTPPragmaheader field name.static final StringThe HTTPProxy-Authenticateheader field name.static final StringThe HTTPProxy-Authorizationheader field name.static final StringThe HTTPRangeheader field name.static final StringThe HTTPRefererheader field name.static final StringThe HTTPRetry-Afterheader field name.static final StringThe HTTPServerheader field name.static final StringThe HTTPSet-Cookieheader field name.static final StringThe HTTPSet-Cookie2header field name.static final StringThe HTTPTEheader field name.static final StringThe HTTPTrailerheader field name.static final StringThe HTTPTransfer-Encodingheader field name.static final StringThe HTTPUpgradeheader field name.static final StringThe HTTPUser-Agentheader field name.static final StringThe HTTPVaryheader field name.static final StringThe HTTPViaheader field name.static final StringThe HTTPWarningheader field name.static final StringThe HTTPWWW-Authenticateheader field name.
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct a new, empty instance of theHttpHeadersobject.HttpHeaders(MultiValueMap<String, String> headers) Construct a newHttpHeadersinstance backed by an existing map.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdd the given, single header value under the given name.voidAdd all the values of the given list to the current list of values for the given key.voidaddAll(MultiValueMap<String, String> values) Add all the values of the givenMultiValueMapto the current values.voidclear()voidRemove the well-known"Content-*"HTTP headers.booleancontainsKey(Object key) booleancontainsValue(Object value) static StringencodeBasicAuth(String username, String password, Charset charset) Encode the given username and password into Basic Authentication credentials.entrySet()booleanvoidforEach(BiConsumer<? super String, ? super List<String>> action) static StringformatHeaders(MultiValueMap<String, String> headers) Helps to format HTTP header values, as HTTP header values themselves can contain comma-separated values, can become confusing with regularMapformatting that also uses commas between entries.Return the list of acceptable media types, as specified by theAcceptheader.Return the list of acceptable charsets, as specified by theAccept-Charsetheader.Return the language ranges from the "Accept-Language" header.Return the list of acceptable media types forPATCHmethods, as specified by theAccept-Patchheader.booleanReturn the value of theAccess-Control-Allow-Credentialsresponse header.Return the value of theAccess-Control-Allow-Headersresponse header.Return the value of theAccess-Control-Allow-Methodsresponse header.Return the value of theAccess-Control-Allow-Originresponse header.Return the value of theAccess-Control-Expose-Headersresponse header.longReturn the value of theAccess-Control-Max-Ageresponse header.Return the value of theAccess-Control-Request-Headersrequest header.Return the value of theAccess-Control-Request-Methodrequest header.getAllow()Return the set of allowedHTTP methods, as specified by theAllowheader.Return the value of theCache-Controlheader.Return the value of theConnectionheader.Return a parsed representation of the Content-Disposition header.Get the firstLocaleof the content languages, as specified by theContent-Languageheader.longReturn the length of the body in bytes, as specified by theContent-Lengthheader.Return the media type of the body, as specified by theContent-Typeheader.longgetDate()Return the date and time at which the message was created, as specified by theDateheader.getETag()Return the entity tag of the body, as specified by theETagheader.getETagValuesAsList(String headerName) Retrieve a combined result from the field values of the ETag header.longReturn the date and time at which the message is no longer valid, as specified by theExpiresheader.protected StringgetFieldValues(String headerName) Retrieve a combined result from the field values of multivalued headers.Return the first header value for the given header name, if any.longgetFirstDate(String headerName) Parse the first header value for the given header name as a date, return -1 if there is no value, or raiseIllegalArgumentExceptionif the value cannot be parsed as a date.getFirstZonedDateTime(String headerName) Parse the first header value for the given header name as a date, returnnullif there is no value, or raiseIllegalArgumentExceptionif the value cannot be parsed as a date.getHost()Return the value of theHostheader, if available.Return the value of theIf-Matchheader.longReturn the value of theIf-Modified-Sinceheader.Return the value of theIf-None-Matchheader.longReturn the value of theIf-Unmodified-Sinceheader.longReturn the time the resource was last changed, as specified by theLast-Modifiedheader.Return the (new) location of a resource as specified by theLocationheader.getOrEmpty(Object headerName) Get the list of header values for the given header name, if any.Return the value of theOriginheader.Return the value of thePragmaheader.getRange()Return the value of theRangeheader.Return the value of theUpgradeheader.getValuesAsList(String headerName) Return all values of a given header name, even if this header is set multiple times.getVary()Return the request header names subject to content negotiation.inthashCode()booleanisEmpty()keySet()voidputIfAbsent(String key, List<String> value) static HttpHeadersreadOnlyHttpHeaders(HttpHeaders headers) Apply a read-onlyHttpHeaderswrapper around the given headers, if necessary.static HttpHeadersreadOnlyHttpHeaders(MultiValueMap<String, String> headers) Apply a read-onlyHttpHeaderswrapper around the given headers, if necessary.voidSet the given, single header value under the given name.voidSet the list of acceptable media types, as specified by theAcceptheader.voidsetAcceptCharset(List<Charset> acceptableCharsets) Set the list of acceptable charsets, as specified by theAccept-Charsetheader.voidsetAcceptLanguage(List<Locale.LanguageRange> languages) Set the acceptable language ranges, as specified by the Accept-Language header.voidsetAcceptLanguageAsLocales(List<Locale> locales) Variant ofsetAcceptLanguage(List)usingLocale's.voidsetAcceptPatch(List<MediaType> mediaTypes) voidsetAccessControlAllowCredentials(boolean allowCredentials) Set the (new) value of theAccess-Control-Allow-Credentialsresponse header.voidsetAccessControlAllowHeaders(List<String> allowedHeaders) Set the (new) value of theAccess-Control-Allow-Headersresponse header.voidsetAccessControlAllowMethods(List<HttpMethod> allowedMethods) Set the (new) value of theAccess-Control-Allow-Methodsresponse header.voidsetAccessControlAllowOrigin(String allowedOrigin) Set the (new) value of theAccess-Control-Allow-Originresponse header.voidsetAccessControlExposeHeaders(List<String> exposedHeaders) Set the (new) value of theAccess-Control-Expose-Headersresponse header.voidsetAccessControlMaxAge(long maxAge) Set the (new) value of theAccess-Control-Max-Ageresponse header.voidsetAccessControlMaxAge(Duration maxAge) Set the (new) value of theAccess-Control-Max-Ageresponse header.voidsetAccessControlRequestHeaders(List<String> requestHeaders) Set the (new) value of theAccess-Control-Request-Headersrequest header.voidsetAccessControlRequestMethod(HttpMethod requestMethod) Set the (new) value of theAccess-Control-Request-Methodrequest header.voidSet the given values under.voidsetAllow(Set<HttpMethod> allowedMethods) Set the set of allowedHTTP methods, as specified by theAllowheader.voidsetBasicAuth(String encodedCredentials) Set the value of the Authorization header to Basic Authentication based on the given encoded credentials.voidsetBasicAuth(String username, String password) Set the value of the Authorization header to Basic Authentication based on the given username and password.voidsetBasicAuth(String username, String password, Charset charset) Set the value of the Authorization header to Basic Authentication based on the given username and password.voidsetBearerAuth(String token) Set the value of the Authorization header to the given Bearer token.voidsetCacheControl(String cacheControl) Set the (new) value of theCache-Controlheader.voidsetCacheControl(CacheControl cacheControl) Set a configuredCacheControlinstance as the new value of theCache-Controlheader.voidsetConnection(String connection) Set the (new) value of theConnectionheader.voidsetConnection(List<String> connection) Set the (new) value of theConnectionheader.voidsetContentDisposition(ContentDisposition contentDisposition) Set the Content-Disposition header.voidsetContentDispositionFormData(String name, String filename) Set theContent-Dispositionheader when creating a"multipart/form-data"request.voidsetContentLanguage(Locale locale) Set theLocaleof the content language, as specified by the Content-Language header.voidsetContentLength(long contentLength) Set the length of the body in bytes, as specified by theContent-Lengthheader.voidsetContentType(MediaType mediaType) Set the media type of the body, as specified by theContent-Typeheader.voidsetDate(long date) Set the date and time at which the message was created, as specified by theDateheader.voidSet the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter.voidSet the date and time at which the message was created, as specified by theDateheader.voidsetDate(ZonedDateTime date) Set the date and time at which the message was created, as specified by theDateheader.voidSet the (new) entity tag of the body, as specified by theETagheader.voidsetExpires(long expires) Set the date and time at which the message is no longer valid, as specified by theExpiresheader.voidsetExpires(Instant expires) Set the date and time at which the message is no longer valid, as specified by theExpiresheader.voidsetExpires(ZonedDateTime expires) Set the duration after which the message is no longer valid, as specified by theExpiresheader.voidsetHost(InetSocketAddress host) Set the (new) value of theHostheader.voidsetIfMatch(String ifMatch) Set the (new) value of theIf-Matchheader.voidsetIfMatch(List<String> ifMatchList) Set the (new) value of theIf-Matchheader.voidsetIfModifiedSince(long ifModifiedSince) Set the (new) value of theIf-Modified-Sinceheader.voidsetIfModifiedSince(Instant ifModifiedSince) Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetIfModifiedSince(ZonedDateTime ifModifiedSince) Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetIfNoneMatch(String ifNoneMatch) Set the (new) value of theIf-None-Matchheader.voidsetIfNoneMatch(List<String> ifNoneMatchList) Set the (new) values of theIf-None-Matchheader.voidsetIfUnmodifiedSince(long ifUnmodifiedSince) Set the (new) value of theIf-Unmodified-Sinceheader.voidsetIfUnmodifiedSince(Instant ifUnmodifiedSince) Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince) Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetInstant(String headerName, Instant date) Set the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter.voidsetLastModified(long lastModified) Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetLastModified(Instant lastModified) Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetLastModified(ZonedDateTime lastModified) Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetLocation(URI location) Set the (new) location of a resource, as specified by theLocationheader.voidSet the (new) value of theOriginheader.voidSet the (new) value of thePragmaheader.voidSets the (new) value of theRangeheader.voidsetUpgrade(String upgrade) Set the (new) value of theUpgradeheader.voidSet the request header names (e.g.voidsetZonedDateTime(String headerName, ZonedDateTime date) Set the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter.intsize()protected StringtoCommaDelimitedString(List<String> headerValues) Turn the given list of header values into a comma-delimited result.Return aMapwith the first values contained in thisMultiValueMap.toString()values()static HttpHeaderswritableHttpHeaders(HttpHeaders headers) Remove any read-only wrapper that may have been previously applied around the given headers viareadOnlyHttpHeaders(HttpHeaders).Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, getOrDefault, merge, remove, replace, replace, replaceAllMethods inherited from interface org.springframework.util.MultiValueMapaddIfAbsent
- 
Field Details- 
ACCEPTThe HTTPAcceptheader field name.
- 
ACCEPT_CHARSETThe HTTPAccept-Charsetheader field name.
- 
ACCEPT_ENCODINGThe HTTPAccept-Encodingheader field name.
- 
ACCEPT_LANGUAGEThe HTTPAccept-Languageheader field name.
- 
ACCEPT_PATCHThe HTTPAccept-Patchheader field name.- Since:
- 5.3.6
- See Also:
 
- 
ACCEPT_RANGESThe HTTPAccept-Rangesheader field name.
- 
ACCESS_CONTROL_ALLOW_CREDENTIALSThe CORSAccess-Control-Allow-Credentialsresponse header field name.- See Also:
 
- 
ACCESS_CONTROL_ALLOW_HEADERSThe CORSAccess-Control-Allow-Headersresponse header field name.- See Also:
 
- 
ACCESS_CONTROL_ALLOW_METHODSThe CORSAccess-Control-Allow-Methodsresponse header field name.- See Also:
 
- 
ACCESS_CONTROL_ALLOW_ORIGINThe CORSAccess-Control-Allow-Originresponse header field name.- See Also:
 
- 
ACCESS_CONTROL_EXPOSE_HEADERSThe CORSAccess-Control-Expose-Headersresponse header field name.- See Also:
 
- 
ACCESS_CONTROL_MAX_AGEThe CORSAccess-Control-Max-Ageresponse header field name.- See Also:
 
- 
ACCESS_CONTROL_REQUEST_HEADERSThe CORSAccess-Control-Request-Headersrequest header field name.- See Also:
 
- 
ACCESS_CONTROL_REQUEST_METHODThe CORSAccess-Control-Request-Methodrequest header field name.- See Also:
 
- 
AGEThe HTTPAgeheader field name.- See Also:
 
- 
ALLOWThe HTTPAllowheader field name.
- 
AUTHORIZATIONThe HTTPAuthorizationheader field name.- See Also:
 
- 
CACHE_CONTROLThe HTTPCache-Controlheader field name.- See Also:
 
- 
CONNECTIONThe HTTPConnectionheader field name.- See Also:
 
- 
CONTENT_ENCODINGThe HTTPContent-Encodingheader field name.
- 
CONTENT_DISPOSITIONThe HTTPContent-Dispositionheader field name.- See Also:
 
- 
CONTENT_LANGUAGEThe HTTPContent-Languageheader field name.
- 
CONTENT_LENGTHThe HTTPContent-Lengthheader field name.
- 
CONTENT_LOCATIONThe HTTPContent-Locationheader field name.
- 
CONTENT_RANGEThe HTTPContent-Rangeheader field name.- See Also:
 
- 
CONTENT_TYPEThe HTTPContent-Typeheader field name.
- 
COOKIEThe HTTPCookieheader field name.
- 
DATEThe HTTPDateheader field name.
- 
ETAGThe HTTPETagheader field name.- See Also:
 
- 
EXPECTThe HTTPExpectheader field name.
- 
EXPIRESThe HTTPExpiresheader field name.- See Also:
 
- 
FROMThe HTTPFromheader field name.
- 
HOSTThe HTTPHostheader field name.- See Also:
 
- 
IF_MATCHThe HTTPIf-Matchheader field name.- See Also:
 
- 
IF_MODIFIED_SINCEThe HTTPIf-Modified-Sinceheader field name.- See Also:
 
- 
IF_NONE_MATCHThe HTTPIf-None-Matchheader field name.- See Also:
 
- 
IF_RANGEThe HTTPIf-Rangeheader field name.- See Also:
 
- 
IF_UNMODIFIED_SINCEThe HTTPIf-Unmodified-Sinceheader field name.- See Also:
 
- 
LAST_MODIFIEDThe HTTPLast-Modifiedheader field name.- See Also:
 
- 
LINKThe HTTPLinkheader field name.- See Also:
 
- 
LOCATIONThe HTTPLocationheader field name.
- 
MAX_FORWARDSThe HTTPMax-Forwardsheader field name.
- 
ORIGINThe HTTPOriginheader field name.- See Also:
 
- 
PRAGMAThe HTTPPragmaheader field name.- See Also:
 
- 
PROXY_AUTHENTICATEThe HTTPProxy-Authenticateheader field name.- See Also:
 
- 
PROXY_AUTHORIZATIONThe HTTPProxy-Authorizationheader field name.- See Also:
 
- 
RANGEThe HTTPRangeheader field name.- See Also:
 
- 
REFERERThe HTTPRefererheader field name.
- 
RETRY_AFTERThe HTTPRetry-Afterheader field name.
- 
SERVERThe HTTPServerheader field name.
- 
SET_COOKIEThe HTTPSet-Cookieheader field name.
- 
SET_COOKIE2The HTTPSet-Cookie2header field name.- See Also:
 
- 
TEThe HTTPTEheader field name.- See Also:
 
- 
TRAILERThe HTTPTrailerheader field name.- See Also:
 
- 
TRANSFER_ENCODINGThe HTTPTransfer-Encodingheader field name.
- 
UPGRADEThe HTTPUpgradeheader field name.- See Also:
 
- 
USER_AGENTThe HTTPUser-Agentheader field name.
- 
VARYThe HTTPVaryheader field name.
- 
VIAThe HTTPViaheader field name.
- 
WARNINGThe HTTPWarningheader field name.- See Also:
 
- 
WWW_AUTHENTICATEThe HTTPWWW-Authenticateheader field name.- See Also:
 
- 
EMPTYAn emptyHttpHeadersinstance (immutable).- Since:
- 5.0
 
 
- 
- 
Constructor Details- 
HttpHeaderspublic HttpHeaders()Construct a new, empty instance of theHttpHeadersobject.This is the common constructor, using a case-insensitive map structure. 
- 
HttpHeadersConstruct a newHttpHeadersinstance backed by an existing map.This constructor is available as an optimization for adapting to existing headers map structures, primarily for internal use within the framework. - Parameters:
- headers- the headers map (expected to operate with case-insensitive keys)
- Since:
- 5.1
 
 
- 
- 
Method Details- 
getOrEmptyGet the list of header values for the given header name, if any.- Parameters:
- headerName- the header name
- Returns:
- the list of header values, or an empty list
- Since:
- 5.2
 
- 
setAcceptSet the list of acceptable media types, as specified by theAcceptheader.
- 
getAcceptReturn the list of acceptable media types, as specified by theAcceptheader.Returns an empty list when the acceptable media types are unspecified. 
- 
setAcceptLanguageSet the acceptable language ranges, as specified by the Accept-Language header.- Since:
- 5.0
 
- 
getAcceptLanguageReturn 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 toLocale.filter(List, Collection).- Throws:
- IllegalArgumentException- if the value cannot be converted to a language range
- Since:
- 5.0
 
- 
setAcceptLanguageAsLocalesVariant ofsetAcceptLanguage(List)usingLocale's.- Since:
- 5.0
 
- 
getAcceptLanguageAsLocales- Returns:
- the locales or an empty list
- Throws:
- IllegalArgumentException- if the value cannot be converted to a locale
- Since:
- 5.0
 
- 
setAcceptPatch- Since:
- 5.3.6
 
- 
getAcceptPatchReturn the list of acceptable media types forPATCHmethods, as specified by theAccept-Patchheader.Returns an empty list when the acceptable media types are unspecified. - Since:
- 5.3.6
 
- 
setAccessControlAllowCredentialspublic void setAccessControlAllowCredentials(boolean allowCredentials) Set the (new) value of theAccess-Control-Allow-Credentialsresponse header.
- 
getAccessControlAllowCredentialspublic boolean getAccessControlAllowCredentials()Return the value of theAccess-Control-Allow-Credentialsresponse header.
- 
setAccessControlAllowHeadersSet the (new) value of theAccess-Control-Allow-Headersresponse header.
- 
getAccessControlAllowHeadersReturn the value of theAccess-Control-Allow-Headersresponse header.
- 
setAccessControlAllowMethodsSet the (new) value of theAccess-Control-Allow-Methodsresponse header.
- 
getAccessControlAllowMethodsReturn the value of theAccess-Control-Allow-Methodsresponse header.
- 
setAccessControlAllowOriginSet the (new) value of theAccess-Control-Allow-Originresponse header.
- 
getAccessControlAllowOriginReturn the value of theAccess-Control-Allow-Originresponse header.
- 
setAccessControlExposeHeadersSet the (new) value of theAccess-Control-Expose-Headersresponse header.
- 
getAccessControlExposeHeadersReturn the value of theAccess-Control-Expose-Headersresponse header.
- 
setAccessControlMaxAgeSet the (new) value of theAccess-Control-Max-Ageresponse header.- Since:
- 5.2
 
- 
setAccessControlMaxAgepublic void setAccessControlMaxAge(long maxAge) Set the (new) value of theAccess-Control-Max-Ageresponse header.
- 
getAccessControlMaxAgepublic long getAccessControlMaxAge()Return the value of theAccess-Control-Max-Ageresponse header.Returns -1 when the max age is unknown. 
- 
setAccessControlRequestHeadersSet the (new) value of theAccess-Control-Request-Headersrequest header.
- 
getAccessControlRequestHeadersReturn the value of theAccess-Control-Request-Headersrequest header.
- 
setAccessControlRequestMethodSet the (new) value of theAccess-Control-Request-Methodrequest header.
- 
getAccessControlRequestMethodReturn the value of theAccess-Control-Request-Methodrequest header.
- 
setAcceptCharsetSet the list of acceptable charsets, as specified by theAccept-Charsetheader.
- 
getAcceptCharsetReturn the list of acceptable charsets, as specified by theAccept-Charsetheader.
- 
setAllowSet the set of allowedHTTP methods, as specified by theAllowheader.
- 
getAllowReturn the set of allowedHTTP methods, as specified by theAllowheader.Returns an empty set when the allowed methods are unspecified. 
- 
setBasicAuthSet the value of the Authorization header to Basic Authentication based on the given username and password.Note that this method only supports characters in the ISO-8859-1character set.- Parameters:
- username- the username
- password- the password
- Throws:
- IllegalArgumentException- if either- useror- passwordcontain characters that cannot be encoded to ISO-8859-1
- Since:
- 5.1
- See Also:
 
- 
setBasicAuthSet 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:
- IllegalArgumentException- if- usernameor- passwordcontains characters that cannot be encoded to the given charset
- Since:
- 5.1
- See Also:
 
- 
setBasicAuthSet the value of the Authorization header to Basic Authentication based on the given encoded credentials.Favor this method over setBasicAuth(String, String)andsetBasicAuth(String, String, Charset)if you wish to cache the encoded credentials.- Parameters:
- encodedCredentials- the encoded credentials
- Throws:
- IllegalArgumentException- if supplied credentials string is- nullor blank
- Since:
- 5.2
- See Also:
 
- 
setBearerAuthSet the value of the Authorization header to the given Bearer token.- Parameters:
- token- the Base64 encoded token
- Since:
- 5.1
- See Also:
 
- 
setCacheControlSet a configuredCacheControlinstance as the new value of theCache-Controlheader.- Since:
- 5.0.5
 
- 
setCacheControlSet the (new) value of theCache-Controlheader.
- 
getCacheControlReturn the value of theCache-Controlheader.
- 
setConnectionSet the (new) value of theConnectionheader.
- 
setConnectionSet the (new) value of theConnectionheader.
- 
getConnectionReturn the value of theConnectionheader.
- 
setContentDispositionFormDataSet theContent-Dispositionheader 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 aResourcefor each part, and then pass that to theRestTemplateorWebClient.- Parameters:
- name- the control name
- filename- the filename (may be- null)
- See Also:
 
- 
setContentDispositionSet the Content-Disposition header.This could be used on a response to indicate if the content is expected to be displayed inline in the browser or as an attachment to be saved locally. It can also be used for a "multipart/form-data"request. For more details see notes onsetContentDispositionFormData(java.lang.String, java.lang.String).- Since:
- 5.0
- See Also:
 
- 
getContentDispositionReturn a parsed representation of the Content-Disposition header.- Since:
- 5.0
- See Also:
 
- 
setContentLanguageSet theLocaleof the content language, as specified by the Content-Language header.Use put(CONTENT_LANGUAGE, list)if you need to set multiple content languages.- Since:
- 5.0
 
- 
getContentLanguageGet the firstLocaleof the content languages, as specified by theContent-Languageheader.Use getValuesAsList(String)if you need to get multiple content languages.- Returns:
- the first Localeof the content languages, ornullif unknown
- Since:
- 5.0
 
- 
setContentLengthpublic void setContentLength(long contentLength) Set the length of the body in bytes, as specified by theContent-Lengthheader.
- 
getContentLengthpublic long getContentLength()Return the length of the body in bytes, as specified by theContent-Lengthheader.Returns -1 when the content-length is unknown. 
- 
setContentTypeSet the media type of the body, as specified by theContent-Typeheader.
- 
getContentTypeReturn the media type of the body, as specified by theContent-Typeheader.Returns nullwhen theContent-Typeheader is not set.- Throws:
- InvalidMediaTypeException- if the media type value cannot be parsed
 
- 
setDateSet the date and time at which the message was created, as specified by theDateheader.- Since:
- 5.2
 
- 
setDateSet the date and time at which the message was created, as specified by theDateheader.- Since:
- 5.2
 
- 
setDatepublic void setDate(long date) Set the date and time at which the message was created, as specified by theDateheader.The date should be specified as the number of milliseconds since January 1, 1970 GMT. 
- 
getDatepublic long getDate()Return the date and time at which the message was created, as specified by theDateheader.The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown. - Throws:
- IllegalArgumentException- if the value cannot be converted to a date
 
- 
setETagSet the (new) entity tag of the body, as specified by theETagheader.
- 
getETagReturn the entity tag of the body, as specified by theETagheader.
- 
setExpiresSet the duration after which the message is no longer valid, as specified by theExpiresheader.- Since:
- 5.0.5
 
- 
setExpiresSet the date and time at which the message is no longer valid, as specified by theExpiresheader.- Since:
- 5.2
 
- 
setExpirespublic void setExpires(long expires) Set the date and time at which the message is no longer valid, as specified by theExpiresheader.The date should be specified as the number of milliseconds since January 1, 1970 GMT. 
- 
getExpirespublic long getExpires()Return the date and time at which the message is no longer valid, as specified by theExpiresheader.The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown. - See Also:
 
- 
setHostSet the (new) value of theHostheader.If the given port is 0, the host header will only contain the host name.- Since:
- 5.0
 
- 
getHostReturn the value of theHostheader, if available.If the header value does not contain a port, the port in the returned address will be 0.- Since:
- 5.0
 
- 
setIfMatchSet the (new) value of theIf-Matchheader.- Since:
- 4.3
 
- 
setIfMatchSet the (new) value of theIf-Matchheader.- Since:
- 4.3
 
- 
getIfMatchReturn the value of theIf-Matchheader.- Throws:
- IllegalArgumentException- if parsing fails
- Since:
- 4.3
 
- 
setIfModifiedSinceSet the time the resource was last changed, as specified by theLast-Modifiedheader.- Since:
- 5.1.4
 
- 
setIfModifiedSinceSet the time the resource was last changed, as specified by theLast-Modifiedheader.- Since:
- 5.1.4
 
- 
setIfModifiedSincepublic void setIfModifiedSince(long ifModifiedSince) Set the (new) value of theIf-Modified-Sinceheader.The date should be specified as the number of milliseconds since January 1, 1970 GMT. 
- 
getIfModifiedSincepublic long getIfModifiedSince()Return the value of theIf-Modified-Sinceheader.The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown. - See Also:
 
- 
setIfNoneMatchSet the (new) value of theIf-None-Matchheader.
- 
setIfNoneMatchSet the (new) values of theIf-None-Matchheader.
- 
getIfNoneMatchReturn the value of theIf-None-Matchheader.- Throws:
- IllegalArgumentException- if parsing fails
 
- 
setIfUnmodifiedSinceSet the time the resource was last changed, as specified by theLast-Modifiedheader.- Since:
- 5.1.4
 
- 
setIfUnmodifiedSinceSet the time the resource was last changed, as specified by theLast-Modifiedheader.- Since:
- 5.1.4
 
- 
setIfUnmodifiedSincepublic void setIfUnmodifiedSince(long ifUnmodifiedSince) Set the (new) value of theIf-Unmodified-Sinceheader.The date should be specified as the number of milliseconds since January 1, 1970 GMT. - Since:
- 4.3
 
- 
getIfUnmodifiedSincepublic long getIfUnmodifiedSince()Return the value of theIf-Unmodified-Sinceheader.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:
 
- 
setLastModifiedSet the time the resource was last changed, as specified by theLast-Modifiedheader.- Since:
- 5.1.4
 
- 
setLastModifiedSet the time the resource was last changed, as specified by theLast-Modifiedheader.- Since:
- 5.1.4
 
- 
setLastModifiedpublic void setLastModified(long lastModified) Set the time the resource was last changed, as specified by theLast-Modifiedheader.The date should be specified as the number of milliseconds since January 1, 1970 GMT. 
- 
getLastModifiedpublic long getLastModified()Return the time the resource was last changed, as specified by theLast-Modifiedheader.The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown. - See Also:
 
- 
setLocationSet the (new) location of a resource, as specified by theLocationheader.
- 
getLocationReturn the (new) location of a resource as specified by theLocationheader.Returns nullwhen the location is unknown.
- 
setOriginSet the (new) value of theOriginheader.
- 
getOriginReturn the value of theOriginheader.
- 
setPragmaSet the (new) value of thePragmaheader.
- 
getPragmaReturn the value of thePragmaheader.
- 
setRangeSets the (new) value of theRangeheader.
- 
getRangeReturn the value of theRangeheader.Returns an empty list when the range is unknown. 
- 
setUpgradeSet the (new) value of theUpgradeheader.
- 
getUpgradeReturn the value of theUpgradeheader.
- 
setVarySet 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
 
- 
getVaryReturn the request header names subject to content negotiation.- Since:
- 4.3
 
- 
setZonedDateTimeSet the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter. The equivalent ofset(String, String)but for date headers.- Since:
- 5.0
 
- 
setInstantSet the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter. The equivalent ofset(String, String)but for date headers.- Since:
- 5.1.4
 
- 
setDateSet the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter. The equivalent ofset(String, String)but for date headers.- Since:
- 3.2.4
- See Also:
 
- 
getFirstDateParse the first header value for the given header name as a date, return -1 if there is no value, or raiseIllegalArgumentExceptionif 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:
 
- 
getFirstZonedDateTimeParse the first header value for the given header name as a date, returnnullif there is no value, or raiseIllegalArgumentExceptionif the value cannot be parsed as a date.- Parameters:
- headerName- the header name
- Returns:
- the parsed date header, or nullif none
- Since:
- 5.0
 
- 
getValuesAsListReturn all values of a given header name, even if this header is set multiple times.This method supports double-quoted values, as described in RFC 9110, section 5.5. - Parameters:
- headerName- the header name
- Returns:
- all associated values
- Since:
- 4.3
 
- 
clearContentHeaderspublic void clearContentHeaders()Remove the well-known"Content-*"HTTP headers.Such headers should be cleared from the response if the intended body can't be written due to errors. - Since:
- 5.2.3
 
- 
getETagValuesAsListRetrieve a combined result from the field values of the ETag header.- Parameters:
- headerName- the header name
- Returns:
- the combined result
- Throws:
- IllegalArgumentException- if parsing fails
- Since:
- 4.3
 
- 
getFieldValuesRetrieve a combined result from the field values of multivalued headers.- Parameters:
- headerName- the header name
- Returns:
- the combined result
- Since:
- 4.3
 
- 
toCommaDelimitedStringTurn 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
 
- 
getFirstReturn the first header value for the given header name, if any.- Specified by:
- getFirstin interface- MultiValueMap<String,- String> 
- Parameters:
- headerName- the header name
- Returns:
- the first header value, or nullif none
 
- 
addAdd the given, single header value under the given name.- Specified by:
- addin interface- MultiValueMap<String,- String> 
- Parameters:
- headerName- the header name
- headerValue- the header value
- Throws:
- UnsupportedOperationException- if adding headers is not supported
- See Also:
 
- 
addAllDescription copied from interface:MultiValueMapAdd all the values of the given list to the current list of values for the given key.- Specified by:
- addAllin interface- MultiValueMap<String,- String> 
- Parameters:
- key- they key
- values- the values to be added
 
- 
addAllDescription copied from interface:MultiValueMapAdd all the values of the givenMultiValueMapto the current values.- Specified by:
- addAllin interface- MultiValueMap<String,- String> 
- Parameters:
- values- the values to be added
 
- 
setSet the given, single header value under the given name.- Specified by:
- setin interface- MultiValueMap<String,- String> 
- Parameters:
- headerName- the header name
- headerValue- the header value
- Throws:
- UnsupportedOperationException- if adding headers is not supported
- See Also:
 
- 
setAllDescription copied from interface:MultiValueMapSet the given values under.- Specified by:
- setAllin interface- MultiValueMap<String,- String> 
- Parameters:
- values- the values.
 
- 
toSingleValueMapDescription copied from interface:MultiValueMapReturn aMapwith the first values contained in thisMultiValueMap.- Specified by:
- toSingleValueMapin interface- MultiValueMap<String,- String> 
- Returns:
- a single value representation of this map
 
- 
sizepublic int size()
- 
isEmptypublic boolean isEmpty()
- 
containsKey- Specified by:
- containsKeyin interface- Map<String,- List<String>> 
 
- 
containsValue- Specified by:
- containsValuein interface- Map<String,- List<String>> 
 
- 
get
- 
put
- 
remove
- 
putAll
- 
clearpublic void clear()
- 
keySet
- 
values
- 
entrySet
- 
forEach
- 
putIfAbsent- Specified by:
- putIfAbsentin interface- Map<String,- List<String>> 
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
- 
readOnlyHttpHeadersApply a read-onlyHttpHeaderswrapper around the given headers, if necessary.Also caches the parsed representations of the "Accept" and "Content-Type" headers. - Parameters:
- headers- the headers to expose
- Returns:
- a read-only variant of the headers, or the original headers as-is
 (in case it happens to be a read-only HttpHeadersinstance already)
- Since:
- 5.3
 
- 
readOnlyHttpHeadersApply a read-onlyHttpHeaderswrapper around the given headers, if necessary.Also caches the parsed representations of the "Accept" and "Content-Type" headers. - Parameters:
- headers- the headers to expose
- Returns:
- a read-only variant of the headers, or the original headers as-is
 
- 
writableHttpHeadersRemove any read-only wrapper that may have been previously applied around the given headers viareadOnlyHttpHeaders(HttpHeaders).- Parameters:
- headers- the headers to expose
- Returns:
- a writable variant of the headers, or the original headers as-is
- Since:
- 5.1.1
 
- 
formatHeadersHelps to format HTTP header values, as HTTP header values themselves can contain comma-separated values, can become confusing with regularMapformatting that also uses commas between entries.- Parameters:
- headers- the headers to format
- Returns:
- the headers to a String
- Since:
- 5.1.4
 
- 
encodeBasicAuthEncode the given username and password into Basic Authentication credentials.The encoded credentials returned by this method can be supplied to setBasicAuth(String)to set the Basic Authentication header.- 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:
- IllegalArgumentException- if- usernameor- passwordcontains characters that cannot be encoded to the given charset
- Since:
- 5.2
- See Also:
 
 
-