Class HttpHeaders
- java.lang.Object
- org.springframework.http.HttpHeaders
- All Implemented Interfaces:
Serializable,Map<String,List<String>>,MultiValueMap<String,String>
- Direct Known Subclasses:
WebSocketHttpHeaders
public class HttpHeaders extends Object implements MultiValueMap<String,String>, Serializable
A data structure representing HTTP request or response headers, mapping String header names to a list of String values, also offering accessors for common application-level data types.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 nameadd(String, String)adds a header value to the list of values for a header nameset(String, String)sets the header value to a single string value
Note that
HttpHeadersgenerally treats header names in a case-insensitive manner.- Since:
- 3.0
- Author:
- Arjen Poutsma, Sebastien Deleuze, Brian Clozel, Juergen Hoeller, Josh Long
- See Also:
- Serialized Form
Field Summary
Fields Modifier and Type Field Description static StringACCEPTThe HTTPAcceptheader field name.static StringACCEPT_CHARSETThe HTTPAccept-Charsetheader field name.static StringACCEPT_ENCODINGThe HTTPAccept-Encodingheader field name.static StringACCEPT_LANGUAGEThe HTTPAccept-Languageheader field name.static StringACCEPT_RANGESThe HTTPAccept-Rangesheader field name.static StringACCESS_CONTROL_ALLOW_CREDENTIALSThe CORSAccess-Control-Allow-Credentialsresponse header field name.static StringACCESS_CONTROL_ALLOW_HEADERSThe CORSAccess-Control-Allow-Headersresponse header field name.static StringACCESS_CONTROL_ALLOW_METHODSThe CORSAccess-Control-Allow-Methodsresponse header field name.static StringACCESS_CONTROL_ALLOW_ORIGINThe CORSAccess-Control-Allow-Originresponse header field name.static StringACCESS_CONTROL_EXPOSE_HEADERSThe CORSAccess-Control-Expose-Headersresponse header field name.static StringACCESS_CONTROL_MAX_AGEThe CORSAccess-Control-Max-Ageresponse header field name.static StringACCESS_CONTROL_REQUEST_HEADERSThe CORSAccess-Control-Request-Headersrequest header field name.static StringACCESS_CONTROL_REQUEST_METHODThe CORSAccess-Control-Request-Methodrequest header field name.static StringAGEThe HTTPAgeheader field name.static StringALLOWThe HTTPAllowheader field name.static StringAUTHORIZATIONThe HTTPAuthorizationheader field name.static StringCACHE_CONTROLThe HTTPCache-Controlheader field name.static StringCONNECTIONThe HTTPConnectionheader field name.static StringCONTENT_DISPOSITIONThe HTTPContent-Dispositionheader field name.static StringCONTENT_ENCODINGThe HTTPContent-Encodingheader field name.static StringCONTENT_LANGUAGEThe HTTPContent-Languageheader field name.static StringCONTENT_LENGTHThe HTTPContent-Lengthheader field name.static StringCONTENT_LOCATIONThe HTTPContent-Locationheader field name.static StringCONTENT_RANGEThe HTTPContent-Rangeheader field name.static StringCONTENT_TYPEThe HTTPContent-Typeheader field name.static StringCOOKIEThe HTTPCookieheader field name.static StringDATEThe HTTPDateheader field name.static StringETAGThe HTTPETagheader field name.static StringEXPECTThe HTTPExpectheader field name.static StringEXPIRESThe HTTPExpiresheader field name.static StringFROMThe HTTPFromheader field name.static StringHOSTThe HTTPHostheader field name.static StringIF_MATCHThe HTTPIf-Matchheader field name.static StringIF_MODIFIED_SINCEThe HTTPIf-Modified-Sinceheader field name.static StringIF_NONE_MATCHThe HTTPIf-None-Matchheader field name.static StringIF_RANGEThe HTTPIf-Rangeheader field name.static StringIF_UNMODIFIED_SINCEThe HTTPIf-Unmodified-Sinceheader field name.static StringLAST_MODIFIEDThe HTTPLast-Modifiedheader field name.static StringLINKThe HTTPLinkheader field name.static StringLOCATIONThe HTTPLocationheader field name.static StringMAX_FORWARDSThe HTTPMax-Forwardsheader field name.static StringORIGINThe HTTPOriginheader field name.static StringPRAGMAThe HTTPPragmaheader field name.static StringPROXY_AUTHENTICATEThe HTTPProxy-Authenticateheader field name.static StringPROXY_AUTHORIZATIONThe HTTPProxy-Authorizationheader field name.static StringRANGEThe HTTPRangeheader field name.static StringREFERERThe HTTPRefererheader field name.static StringRETRY_AFTERThe HTTPRetry-Afterheader field name.static StringSERVERThe HTTPServerheader field name.static StringSET_COOKIEThe HTTPSet-Cookieheader field name.static StringSET_COOKIE2The HTTPSet-Cookie2header field name.static StringTEThe HTTPTEheader field name.static StringTRAILERThe HTTPTrailerheader field name.static StringTRANSFER_ENCODINGThe HTTPTransfer-Encodingheader field name.static StringUPGRADEThe HTTPUpgradeheader field name.static StringUSER_AGENTThe HTTPUser-Agentheader field name.static StringVARYThe HTTPVaryheader field name.static StringVIAThe HTTPViaheader field name.static StringWARNINGThe HTTPWarningheader field name.static StringWWW_AUTHENTICATEThe HTTPWWW-Authenticateheader field name.
Constructor Summary
Constructors Constructor Description HttpHeaders()Construct a new, empty instance of theHttpHeadersobject.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidadd(String headerName, String headerValue)Add the given, single header value under the given name.voidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)Set<Map.Entry<String,List<String>>>entrySet()booleanequals(Object other)List<String>get(Object key)List<MediaType>getAccept()Return the list of acceptable media types, as specified by theAcceptheader.List<Charset>getAcceptCharset()Return the list of acceptable charsets, as specified by theAccept-Charsetheader.booleangetAccessControlAllowCredentials()Return the value of theAccess-Control-Allow-Credentialsresponse header.List<String>getAccessControlAllowHeaders()Return the value of theAccess-Control-Allow-Headersresponse header.List<HttpMethod>getAccessControlAllowMethods()Return the value of theAccess-Control-Allow-Methodsresponse header.StringgetAccessControlAllowOrigin()Return the value of theAccess-Control-Allow-Originresponse header.List<String>getAccessControlExposeHeaders()Return the value of theAccess-Control-Expose-Headersresponse header.longgetAccessControlMaxAge()Return the value of theAccess-Control-Max-Ageresponse header.List<String>getAccessControlRequestHeaders()Return the value of theAccess-Control-Request-Headersrequest header.HttpMethodgetAccessControlRequestMethod()Return the value of theAccess-Control-Request-Methodrequest header.Set<HttpMethod>getAllow()Return the set of allowedHTTP methods, as specified by theAllowheader.StringgetCacheControl()Return the value of theCache-Controlheader.List<String>getConnection()Return the value of theConnectionheader.longgetContentLength()Return the length of the body in bytes, as specified by theContent-Lengthheader.MediaTypegetContentType()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.StringgetETag()Return the entity tag of the body, as specified by theETagheader.protected List<String>getETagValuesAsList(String headerName)Retrieve a combined result from the field values of the ETag header.longgetExpires()Return 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 multi-valued headers.StringgetFirst(String headerName)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.List<String>getIfMatch()Return the value of theIf-Matchheader.longgetIfModifiedSince()Return the value of theIf-Modified-Sinceheader.List<String>getIfNoneMatch()Return the value of theIf-None-Matchheader.longgetIfUnmodifiedSince()Return the value of theIf-Unmodified-Sinceheader.longgetLastModified()Return the time the resource was last changed, as specified by theLast-Modifiedheader.URIgetLocation()Return the (new) location of a resource as specified by theLocationheader.StringgetOrigin()Return the value of theOriginheader.StringgetPragma()Return the value of thePragmaheader.List<HttpRange>getRange()Return the value of theRangeheader.StringgetUpgrade()Return the value of theUpgradeheader.List<String>getValuesAsList(String headerName)Return all values of a given header name, even if this header is set multiple times.List<String>getVary()Return the request header names subject to content negotiation.inthashCode()booleanisEmpty()Set<String>keySet()List<String>put(String key, List<String> value)voidputAll(Map<? extends String,? extends List<String>> map)static HttpHeadersreadOnlyHttpHeaders(HttpHeaders headers)Return anHttpHeadersobject that can only be read, not written to.List<String>remove(Object key)voidset(String headerName, String headerValue)Set the given, single header value under the given name.voidsetAccept(List<MediaType> acceptableMediaTypes)Set 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.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.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.voidsetAll(Map<String,String> values)Set the given values under.voidsetAllow(Set<HttpMethod> allowedMethods)Set the set of allowedHTTP methods, as specified by theAllowheader.voidsetCacheControl(String cacheControl)Set 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.voidsetContentDispositionFormData(String name, String filename)Set theContent-Dispositionheader when creating a"multipart/form-data"request.voidsetContentDispositionFormData(String name, String filename, Charset charset)Deprecated.deprecated in 4.3.11 and removed from 5.0; as per RFC 7578, Section 4.2, an RFC 5987 style encoding should not be used for multipart/form-data requests.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.voidsetDate(String headerName, long date)Set the given date under the given header name after formatting it as a string using the pattern"EEE, dd MMM yyyy HH:mm:ss zzz".voidsetETag(String etag)Set 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.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.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.voidsetLastModified(long 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.voidsetOrigin(String origin)Set the (new) value of theOriginheader.voidsetPragma(String pragma)Set the (new) value of thePragmaheader.voidsetRange(List<HttpRange> ranges)Sets the (new) value of theRangeheader.voidsetUpgrade(String upgrade)Set the (new) value of theUpgradeheader.voidsetVary(List<String> requestHeaders)Set the request header names (e.g.intsize()protected StringtoCommaDelimitedString(List<String> headerValues)Turn the given list of header values into a comma-delimited result.Map<String,String>toSingleValueMap()Return aMapwith the first values contained in thisMultiValueMap.StringtoString()Collection<List<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
Field Detail
ACCEPT_CHARSET
public static final String ACCEPT_CHARSET
The HTTPAccept-Charsetheader field name.
ACCEPT_ENCODING
public static final String ACCEPT_ENCODING
The HTTPAccept-Encodingheader field name.
ACCEPT_LANGUAGE
public static final String ACCEPT_LANGUAGE
The HTTPAccept-Languageheader field name.
ACCEPT_RANGES
public static final String ACCEPT_RANGES
The HTTPAccept-Rangesheader field name.
ACCESS_CONTROL_ALLOW_CREDENTIALS
public static final String ACCESS_CONTROL_ALLOW_CREDENTIALS
The CORSAccess-Control-Allow-Credentialsresponse header field name.- See Also:
- CORS W3C recommendation, Constant Field Values
ACCESS_CONTROL_ALLOW_HEADERS
public static final String ACCESS_CONTROL_ALLOW_HEADERS
The CORSAccess-Control-Allow-Headersresponse header field name.- See Also:
- CORS W3C recommendation, Constant Field Values
ACCESS_CONTROL_ALLOW_METHODS
public static final String ACCESS_CONTROL_ALLOW_METHODS
The CORSAccess-Control-Allow-Methodsresponse header field name.- See Also:
- CORS W3C recommendation, Constant Field Values
ACCESS_CONTROL_ALLOW_ORIGIN
public static final String ACCESS_CONTROL_ALLOW_ORIGIN
The CORSAccess-Control-Allow-Originresponse header field name.- See Also:
- CORS W3C recommendation, Constant Field Values
ACCESS_CONTROL_EXPOSE_HEADERS
public static final String ACCESS_CONTROL_EXPOSE_HEADERS
The CORSAccess-Control-Expose-Headersresponse header field name.- See Also:
- CORS W3C recommendation, Constant Field Values
ACCESS_CONTROL_MAX_AGE
public static final String ACCESS_CONTROL_MAX_AGE
The CORSAccess-Control-Max-Ageresponse header field name.- See Also:
- CORS W3C recommendation, Constant Field Values
ACCESS_CONTROL_REQUEST_HEADERS
public static final String ACCESS_CONTROL_REQUEST_HEADERS
The CORSAccess-Control-Request-Headersrequest header field name.- See Also:
- CORS W3C recommendation, Constant Field Values
ACCESS_CONTROL_REQUEST_METHOD
public static final String ACCESS_CONTROL_REQUEST_METHOD
The CORSAccess-Control-Request-Methodrequest header field name.- See Also:
- CORS W3C recommendation, Constant Field Values
AGE
public static final String AGE
The HTTPAgeheader field name.- See Also:
- Section 5.1 of RFC 7234, Constant Field Values
AUTHORIZATION
public static final String AUTHORIZATION
The HTTPAuthorizationheader field name.- See Also:
- Section 4.2 of RFC 7235, Constant Field Values
CACHE_CONTROL
public static final String CACHE_CONTROL
The HTTPCache-Controlheader field name.- See Also:
- Section 5.2 of RFC 7234, Constant Field Values
CONNECTION
public static final String CONNECTION
The HTTPConnectionheader field name.- See Also:
- Section 6.1 of RFC 7230, Constant Field Values
CONTENT_ENCODING
public static final String CONTENT_ENCODING
The HTTPContent-Encodingheader field name.
CONTENT_DISPOSITION
public static final String CONTENT_DISPOSITION
The HTTPContent-Dispositionheader field name.- See Also:
- RFC 6266, Constant Field Values
CONTENT_LANGUAGE
public static final String CONTENT_LANGUAGE
The HTTPContent-Languageheader field name.
CONTENT_LENGTH
public static final String CONTENT_LENGTH
The HTTPContent-Lengthheader field name.
CONTENT_LOCATION
public static final String CONTENT_LOCATION
The HTTPContent-Locationheader field name.
CONTENT_RANGE
public static final String CONTENT_RANGE
The HTTPContent-Rangeheader field name.- See Also:
- Section 4.2 of RFC 7233, Constant Field Values
CONTENT_TYPE
public static final String CONTENT_TYPE
The HTTPContent-Typeheader field name.
ETAG
public static final String ETAG
The HTTPETagheader field name.- See Also:
- Section 2.3 of RFC 7232, Constant Field Values
EXPIRES
public static final String EXPIRES
The HTTPExpiresheader field name.- See Also:
- Section 5.3 of RFC 7234, Constant Field Values
HOST
public static final String HOST
The HTTPHostheader field name.- See Also:
- Section 5.4 of RFC 7230, Constant Field Values
IF_MATCH
public static final String IF_MATCH
The HTTPIf-Matchheader field name.- See Also:
- Section 3.1 of RFC 7232, Constant Field Values
IF_MODIFIED_SINCE
public static final String IF_MODIFIED_SINCE
The HTTPIf-Modified-Sinceheader field name.- See Also:
- Section 3.3 of RFC 7232, Constant Field Values
IF_NONE_MATCH
public static final String IF_NONE_MATCH
The HTTPIf-None-Matchheader field name.- See Also:
- Section 3.2 of RFC 7232, Constant Field Values
IF_RANGE
public static final String IF_RANGE
The HTTPIf-Rangeheader field name.- See Also:
- Section 3.2 of RFC 7233, Constant Field Values
IF_UNMODIFIED_SINCE
public static final String IF_UNMODIFIED_SINCE
The HTTPIf-Unmodified-Sinceheader field name.- See Also:
- Section 3.4 of RFC 7232, Constant Field Values
LAST_MODIFIED
public static final String LAST_MODIFIED
The HTTPLast-Modifiedheader field name.- See Also:
- Section 2.2 of RFC 7232, Constant Field Values
LINK
public static final String LINK
The HTTPLinkheader field name.- See Also:
- RFC 5988, Constant Field Values
MAX_FORWARDS
public static final String MAX_FORWARDS
The HTTPMax-Forwardsheader field name.
ORIGIN
public static final String ORIGIN
The HTTPOriginheader field name.- See Also:
- RFC 6454, Constant Field Values
PRAGMA
public static final String PRAGMA
The HTTPPragmaheader field name.- See Also:
- Section 5.4 of RFC 7234, Constant Field Values
PROXY_AUTHENTICATE
public static final String PROXY_AUTHENTICATE
The HTTPProxy-Authenticateheader field name.- See Also:
- Section 4.3 of RFC 7235, Constant Field Values
PROXY_AUTHORIZATION
public static final String PROXY_AUTHORIZATION
The HTTPProxy-Authorizationheader field name.- See Also:
- Section 4.4 of RFC 7235, Constant Field Values
RANGE
public static final String RANGE
The HTTPRangeheader field name.- See Also:
- Section 3.1 of RFC 7233, Constant Field Values
RETRY_AFTER
public static final String RETRY_AFTER
The HTTPRetry-Afterheader field name.
SET_COOKIE
public static final String SET_COOKIE
The HTTPSet-Cookieheader field name.
SET_COOKIE2
public static final String SET_COOKIE2
The HTTPSet-Cookie2header field name.- See Also:
- RFC 2965, Constant Field Values
TE
public static final String TE
The HTTPTEheader field name.- See Also:
- Section 4.3 of RFC 7230, Constant Field Values
TRAILER
public static final String TRAILER
The HTTPTrailerheader field name.- See Also:
- Section 4.4 of RFC 7230, Constant Field Values
TRANSFER_ENCODING
public static final String TRANSFER_ENCODING
The HTTPTransfer-Encodingheader field name.
UPGRADE
public static final String UPGRADE
The HTTPUpgradeheader field name.- See Also:
- Section 6.7 of RFC 7230, Constant Field Values
USER_AGENT
public static final String USER_AGENT
The HTTPUser-Agentheader field name.
WARNING
public static final String WARNING
The HTTPWarningheader field name.- See Also:
- Section 5.5 of RFC 7234, Constant Field Values
WWW_AUTHENTICATE
public static final String WWW_AUTHENTICATE
The HTTPWWW-Authenticateheader field name.- See Also:
- Section 4.1 of RFC 7235, Constant Field Values
Constructor Detail
HttpHeaders
public HttpHeaders()
Construct a new, empty instance of theHttpHeadersobject.
Method Detail
setAccept
public void setAccept(List<MediaType> acceptableMediaTypes)
Set the list of acceptable media types, as specified by theAcceptheader.
getAccept
public List<MediaType> getAccept()
Return the list of acceptable media types, as specified by theAcceptheader.Returns an empty list when the acceptable media types are unspecified.
setAccessControlAllowCredentials
public void setAccessControlAllowCredentials(boolean allowCredentials)
Set the (new) value of theAccess-Control-Allow-Credentialsresponse header.
getAccessControlAllowCredentials
public boolean getAccessControlAllowCredentials()
Return the value of theAccess-Control-Allow-Credentialsresponse header.
setAccessControlAllowHeaders
public void setAccessControlAllowHeaders(List<String> allowedHeaders)
Set the (new) value of theAccess-Control-Allow-Headersresponse header.
getAccessControlAllowHeaders
public List<String> getAccessControlAllowHeaders()
Return the value of theAccess-Control-Allow-Headersresponse header.
setAccessControlAllowMethods
public void setAccessControlAllowMethods(List<HttpMethod> allowedMethods)
Set the (new) value of theAccess-Control-Allow-Methodsresponse header.
getAccessControlAllowMethods
public List<HttpMethod> getAccessControlAllowMethods()
Return the value of theAccess-Control-Allow-Methodsresponse header.
setAccessControlAllowOrigin
public void setAccessControlAllowOrigin(String allowedOrigin)
Set the (new) value of theAccess-Control-Allow-Originresponse header.
getAccessControlAllowOrigin
public String getAccessControlAllowOrigin()
Return the value of theAccess-Control-Allow-Originresponse header.
setAccessControlExposeHeaders
public void setAccessControlExposeHeaders(List<String> exposedHeaders)
Set the (new) value of theAccess-Control-Expose-Headersresponse header.
getAccessControlExposeHeaders
public List<String> getAccessControlExposeHeaders()
Return the value of theAccess-Control-Expose-Headersresponse header.
setAccessControlMaxAge
public void setAccessControlMaxAge(long maxAge)
Set the (new) value of theAccess-Control-Max-Ageresponse header.
getAccessControlMaxAge
public long getAccessControlMaxAge()
Return the value of theAccess-Control-Max-Ageresponse header.Returns -1 when the max age is unknown.
setAccessControlRequestHeaders
public void setAccessControlRequestHeaders(List<String> requestHeaders)
Set the (new) value of theAccess-Control-Request-Headersrequest header.
getAccessControlRequestHeaders
public List<String> getAccessControlRequestHeaders()
Return the value of theAccess-Control-Request-Headersrequest header.
setAccessControlRequestMethod
public void setAccessControlRequestMethod(HttpMethod requestMethod)
Set the (new) value of theAccess-Control-Request-Methodrequest header.
getAccessControlRequestMethod
public HttpMethod getAccessControlRequestMethod()
Return the value of theAccess-Control-Request-Methodrequest header.
setAcceptCharset
public void setAcceptCharset(List<Charset> acceptableCharsets)
Set the list of acceptable charsets, as specified by theAccept-Charsetheader.
getAcceptCharset
public List<Charset> getAcceptCharset()
Return the list of acceptable charsets, as specified by theAccept-Charsetheader.
setAllow
public void setAllow(Set<HttpMethod> allowedMethods)
Set the set of allowedHTTP methods, as specified by theAllowheader.
getAllow
public Set<HttpMethod> getAllow()
Return the set of allowedHTTP methods, as specified by theAllowheader.Returns an empty set when the allowed methods are unspecified.
setCacheControl
public void setCacheControl(String cacheControl)
Set the (new) value of theCache-Controlheader.
getCacheControl
public String getCacheControl()
Return the value of theCache-Controlheader.
setConnection
public void setConnection(String connection)
Set the (new) value of theConnectionheader.
setConnection
public void setConnection(List<String> connection)
Set the (new) value of theConnectionheader.
getConnection
public List<String> getConnection()
Return the value of theConnectionheader.
setContentDispositionFormData
public void setContentDispositionFormData(String name, String filename)
Set theContent-Dispositionheader when creating a"multipart/form-data"request. The given filename is formatted as a quoted-string, as defined in RFC 2616, section 2.2, and any quote characters within the filename value will be escaped with a backslash, e.g."foo\"bar.txt"becomes"foo\\\"bar.txt".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 namefilename- the filename (may benull)
setContentDispositionFormData
@Deprecated public void setContentDispositionFormData(String name, String filename, Charset charset)
Deprecated.deprecated in 4.3.11 and removed from 5.0; as per RFC 7578, Section 4.2, an RFC 5987 style encoding should not be used for multipart/form-data requests. Furthermore there should be no reason for applications to set this header explicitly; for more details also readsetContentDispositionFormData(String, String)Set the (new) value of theContent-Dispositionheader forform-data, optionally encoding the filename using the RFC 5987.Only the US-ASCII, UTF-8 and ISO-8859-1 charsets are supported.
- Parameters:
name- the control namefilename- the filename (may benull)charset- the charset used for the filename (may benull)
setContentLength
public void setContentLength(long contentLength)
Set the length of the body in bytes, as specified by theContent-Lengthheader.
getContentLength
public long getContentLength()
Return the length of the body in bytes, as specified by theContent-Lengthheader.Returns -1 when the content-length is unknown.
setContentType
public void setContentType(MediaType mediaType)
Set the media type of the body, as specified by theContent-Typeheader.
getContentType
public MediaType getContentType()
Return the media type of the body, as specified by theContent-Typeheader.Returns
nullwhen 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 theDateheader.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 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
setETag
public void setETag(String etag)
Set the (new) entity tag of the body, as specified by theETagheader.
setExpires
public 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.
getExpires
public 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.
setIfMatch
public void setIfMatch(String ifMatch)
Set the (new) value of theIf-Matchheader.- Since:
- 4.3
setIfMatch
public void setIfMatch(List<String> ifMatchList)
Set the (new) value of theIf-Matchheader.- Since:
- 4.3
getIfMatch
public List<String> getIfMatch()
Return the value of theIf-Matchheader.- Since:
- 4.3
setIfModifiedSince
public 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.
getIfModifiedSince
public 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.
setIfNoneMatch
public void setIfNoneMatch(String ifNoneMatch)
Set the (new) value of theIf-None-Matchheader.
setIfNoneMatch
public void setIfNoneMatch(List<String> ifNoneMatchList)
Set the (new) values of theIf-None-Matchheader.
getIfNoneMatch
public List<String> getIfNoneMatch()
Return the value of theIf-None-Matchheader.
setIfUnmodifiedSince
public 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
getIfUnmodifiedSince
public 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
setLastModified
public 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.
getLastModified
public 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.
setLocation
public void setLocation(URI location)
Set the (new) location of a resource, as specified by theLocationheader.
getLocation
public URI getLocation()
Return the (new) location of a resource as specified by theLocationheader.Returns
nullwhen the location is unknown.
getRange
public List<HttpRange> getRange()
Return the value of theRangeheader.Returns an empty list when the range is unknown.
setUpgrade
public void setUpgrade(String upgrade)
Set the (new) value of theUpgradeheader.
getUpgrade
public String getUpgrade()
Return the value of theUpgradeheader.
setVary
public void setVary(List<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 List<String> getVary()
Return the request header names subject to content negotiation.- Since:
- 4.3
setDate
public void setDate(String headerName, long date)
Set the given date under the given header name after formatting it as a string using the pattern"EEE, dd MMM yyyy HH:mm:ss zzz". The equivalent ofset(String, String)but for date headers.- Since:
- 3.2.4
getFirstDate
public long getFirstDate(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.- Parameters:
headerName- the header name- Returns:
- the parsed date header, or -1 if none
- Since:
- 3.2.4
getValuesAsList
public List<String> getValuesAsList(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 List<String> getETagValuesAsList(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
protected String getFieldValues(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 String toCommaDelimitedString(List<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
public String getFirst(String headerName)
Return the first header value for the given header name, if any.- Specified by:
getFirstin interfaceMultiValueMap<String,String>- Parameters:
headerName- the header name- Returns:
- the first header value, or
nullif none
add
public void add(String headerName, String headerValue)
Add the given, single header value under the given name.- Specified by:
addin interfaceMultiValueMap<String,String>- Parameters:
headerName- the header nameheaderValue- the header value- Throws:
UnsupportedOperationException- if adding headers is not supported- See Also:
put(String, List),set(String, String)
set
public void set(String headerName, String headerValue)
Set the given, single header value under the given name.- Specified by:
setin interfaceMultiValueMap<String,String>- Parameters:
headerName- the header nameheaderValue- the header value- Throws:
UnsupportedOperationException- if adding headers is not supported- See Also:
put(String, List),add(String, String)
setAll
public void setAll(Map<String,String> values)
Description copied from interface:MultiValueMapSet the given values under.- Specified by:
setAllin interfaceMultiValueMap<String,String>- Parameters:
values- the values.
toSingleValueMap
public Map<String,String> toSingleValueMap()
Description copied from interface:MultiValueMapReturn aMapwith the first values contained in thisMultiValueMap.- Specified by:
toSingleValueMapin interfaceMultiValueMap<String,String>- Returns:
- a single value representation of this map
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKeyin interfaceMap<String,List<String>>
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValuein interfaceMap<String,List<String>>
values
public Collection<List<String>> values()
hashCode
public int hashCode()
readOnlyHttpHeaders
public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
Return anHttpHeadersobject that can only be read, not written to.