public class HttpHeaders extends Object implements MultiValueMap<String,String>, Serializable
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 valueNote that HttpHeaders
generally treats header names in a case-insensitive manner.
Modifier and Type | Field and Description |
---|---|
static String |
ACCEPT
The HTTP
Accept header field name. |
static String |
ACCEPT_CHARSET
The HTTP
Accept-Charset header field name. |
static String |
ACCEPT_ENCODING
The HTTP
Accept-Encoding header field name. |
static String |
ACCEPT_LANGUAGE
The HTTP
Accept-Language header field name. |
static String |
ACCEPT_PATCH
The HTTP
Accept-Patch header field name. |
static String |
ACCEPT_RANGES
The HTTP
Accept-Ranges header field name. |
static String |
ACCESS_CONTROL_ALLOW_CREDENTIALS
The CORS
Access-Control-Allow-Credentials response header field name. |
static String |
ACCESS_CONTROL_ALLOW_HEADERS
The CORS
Access-Control-Allow-Headers response header field name. |
static String |
ACCESS_CONTROL_ALLOW_METHODS
The CORS
Access-Control-Allow-Methods response header field name. |
static String |
ACCESS_CONTROL_ALLOW_ORIGIN
The CORS
Access-Control-Allow-Origin response header field name. |
static String |
ACCESS_CONTROL_EXPOSE_HEADERS
The CORS
Access-Control-Expose-Headers response header field name. |
static String |
ACCESS_CONTROL_MAX_AGE
The CORS
Access-Control-Max-Age response header field name. |
static String |
ACCESS_CONTROL_REQUEST_HEADERS
The CORS
Access-Control-Request-Headers request header field name. |
static String |
ACCESS_CONTROL_REQUEST_METHOD
The CORS
Access-Control-Request-Method request header field name. |
static String |
AGE
The HTTP
Age header field name. |
static String |
ALLOW
The HTTP
Allow header field name. |
static String |
AUTHORIZATION
The HTTP
Authorization header field name. |
static String |
CACHE_CONTROL
The HTTP
Cache-Control header field name. |
static String |
CONNECTION
The HTTP
Connection header field name. |
static String |
CONTENT_DISPOSITION
The HTTP
Content-Disposition header field name. |
static String |
CONTENT_ENCODING
The HTTP
Content-Encoding header field name. |
static String |
CONTENT_LANGUAGE
The HTTP
Content-Language header field name. |
static String |
CONTENT_LENGTH
The HTTP
Content-Length header field name. |
static String |
CONTENT_LOCATION
The HTTP
Content-Location header field name. |
static String |
CONTENT_RANGE
The HTTP
Content-Range header field name. |
static String |
CONTENT_TYPE
The HTTP
Content-Type header field name. |
static String |
COOKIE
The HTTP
Cookie header field name. |
static String |
DATE
The HTTP
Date header field name. |
static HttpHeaders |
EMPTY
An empty
HttpHeaders instance (immutable). |
static String |
ETAG
The HTTP
ETag header field name. |
static String |
EXPECT
The HTTP
Expect header field name. |
static String |
EXPIRES
The HTTP
Expires header field name. |
static String |
FROM
The HTTP
From header field name. |
static String |
HOST
The HTTP
Host header field name. |
static String |
IF_MATCH
The HTTP
If-Match header field name. |
static String |
IF_MODIFIED_SINCE
The HTTP
If-Modified-Since header field name. |
static String |
IF_NONE_MATCH
The HTTP
If-None-Match header field name. |
static String |
IF_RANGE
The HTTP
If-Range header field name. |
static String |
IF_UNMODIFIED_SINCE
The HTTP
If-Unmodified-Since header field name. |
static String |
LAST_MODIFIED
The HTTP
Last-Modified header field name. |
static String |
LINK
The HTTP
Link header field name. |
static String |
LOCATION
The HTTP
Location header field name. |
static String |
MAX_FORWARDS
The HTTP
Max-Forwards header field name. |
static String |
ORIGIN
The HTTP
Origin header field name. |
static String |
PRAGMA
The HTTP
Pragma header field name. |
static String |
PROXY_AUTHENTICATE
The HTTP
Proxy-Authenticate header field name. |
static String |
PROXY_AUTHORIZATION
The HTTP
Proxy-Authorization header field name. |
static String |
RANGE
The HTTP
Range header field name. |
static String |
REFERER
The HTTP
Referer header field name. |
static String |
RETRY_AFTER
The HTTP
Retry-After header field name. |
static String |
SERVER
The HTTP
Server header field name. |
static String |
SET_COOKIE
The HTTP
Set-Cookie header field name. |
static String |
SET_COOKIE2
The HTTP
Set-Cookie2 header field name. |
static String |
TE
The HTTP
TE header field name. |
static String |
TRAILER
The HTTP
Trailer header field name. |
static String |
TRANSFER_ENCODING
The HTTP
Transfer-Encoding header field name. |
static String |
UPGRADE
The HTTP
Upgrade header field name. |
static String |
USER_AGENT
The HTTP
User-Agent header field name. |
static String |
VARY
The HTTP
Vary header field name. |
static String |
VIA
The HTTP
Via header field name. |
static String |
WARNING
The HTTP
Warning header field name. |
static String |
WWW_AUTHENTICATE
The HTTP
WWW-Authenticate header field name. |
Constructor and Description |
---|
HttpHeaders()
Construct a new, empty instance of the
HttpHeaders object. |
HttpHeaders(MultiValueMap<String,String> headers)
Construct a new
HttpHeaders instance backed by an existing map. |
Modifier and Type | Method and Description |
---|---|
void |
add(String headerName,
String headerValue)
Add the given, single header value under the given name.
|
void |
addAll(MultiValueMap<String,String> values)
Add all the values of the given
MultiValueMap to the current values. |
void |
addAll(String key,
List<? extends String> values)
Add all the values of the given list to the current list of values for the given key.
|
void |
clear() |
void |
clearContentHeaders()
Remove the well-known
"Content-*" HTTP headers. |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
static String |
encodeBasicAuth(String username,
String password,
Charset charset)
Encode the given username and password into Basic Authentication credentials.
|
Set<Map.Entry<String,List<String>>> |
entrySet() |
boolean |
equals(Object other) |
static String |
formatHeaders(MultiValueMap<String,String> headers)
Helps to format HTTP header values, as HTTP header values themselves can
contain comma-separated values, can become confusing with regular
Map formatting that also uses commas between entries. |
List<String> |
get(Object key) |
List<MediaType> |
getAccept()
Return the list of acceptable media types,
as specified by the
Accept header. |
List<Charset> |
getAcceptCharset()
Return the list of acceptable charsets,
as specified by the
Accept-Charset header. |
List<Locale.LanguageRange> |
getAcceptLanguage()
Return the language ranges from the "Accept-Language" header.
|
List<Locale> |
getAcceptLanguageAsLocales()
|
List<MediaType> |
getAcceptPatch()
Return the list of acceptable media types for
PATCH methods, as specified by the Accept-Patch header. |
boolean |
getAccessControlAllowCredentials()
Return the value of the
Access-Control-Allow-Credentials response header. |
List<String> |
getAccessControlAllowHeaders()
Return the value of the
Access-Control-Allow-Headers response header. |
List<HttpMethod> |
getAccessControlAllowMethods()
Return the value of the
Access-Control-Allow-Methods response header. |
String |
getAccessControlAllowOrigin()
Return the value of the
Access-Control-Allow-Origin response header. |
List<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. |
List<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. |
Set<HttpMethod> |
getAllow()
Return the set of allowed
HTTP methods ,
as specified by the Allow header. |
String |
getCacheControl()
Return the value of the
Cache-Control header. |
List<String> |
getConnection()
Return the value of the
Connection header. |
ContentDisposition |
getContentDisposition()
Return a parsed representation of the Content-Disposition header.
|
Locale |
getContentLanguage()
Get 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. |
String |
getETag()
Return the entity tag of the body, as specified by the
ETag header. |
protected List<String> |
getETagValuesAsList(String name)
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 String |
getFieldValues(String headerName)
Retrieve a combined result from the field values of multivalued headers.
|
String |
getFirst(String headerName)
Return the first header value for the given header name, if any.
|
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 raise
IllegalArgumentException
if the value cannot be parsed as a date. |
ZonedDateTime |
getFirstZonedDateTime(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. |
InetSocketAddress |
getHost()
Return the value of the
Host header, if available. |
List<String> |
getIfMatch()
Return the value of the
If-Match header. |
long |
getIfModifiedSince()
Return the value of the
If-Modified-Since header. |
List<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. |
URI |
getLocation()
Return the (new) location of a resource
as specified by the
Location header. |
List<String> |
getOrEmpty(Object headerName)
Get the list of header values for the given header name, if any.
|
String |
getOrigin()
Return the value of the
Origin header. |
String |
getPragma()
Return the value of the
Pragma header. |
List<HttpRange> |
getRange()
Return the value of the
Range header. |
String |
getUpgrade()
Return the value of the
Upgrade header. |
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.
|
int |
hashCode() |
boolean |
isEmpty() |
Set<String> |
keySet() |
List<String> |
put(String key,
List<String> value) |
void |
putAll(Map<? extends String,? extends List<String>> map) |
static HttpHeaders |
readOnlyHttpHeaders(HttpHeaders headers)
Apply a read-only
HttpHeaders wrapper around the given headers, if necessary. |
static HttpHeaders |
readOnlyHttpHeaders(MultiValueMap<String,String> headers)
Apply a read-only
HttpHeaders wrapper around the given headers, if necessary. |
List<String> |
remove(Object key) |
void |
set(String headerName,
String headerValue)
Set the given, single header value under the given name.
|
void |
setAccept(List<MediaType> acceptableMediaTypes)
Set the list of acceptable media types,
as specified by the
Accept header. |
void |
setAcceptCharset(List<Charset> acceptableCharsets)
Set the list of acceptable charsets,
as specified by the
Accept-Charset header. |
void |
setAcceptLanguage(List<Locale.LanguageRange> languages)
Set the acceptable language ranges, as specified by the
Accept-Language header.
|
void |
setAcceptLanguageAsLocales(List<Locale> locales)
Variant of
setAcceptLanguage(List) using Locale 's. |
void |
setAcceptPatch(List<MediaType> mediaTypes)
|
void |
setAccessControlAllowCredentials(boolean allowCredentials)
Set the (new) value of the
Access-Control-Allow-Credentials response header. |
void |
setAccessControlAllowHeaders(List<String> allowedHeaders)
Set the (new) value of the
Access-Control-Allow-Headers response header. |
void |
setAccessControlAllowMethods(List<HttpMethod> allowedMethods)
Set the (new) value of the
Access-Control-Allow-Methods response header. |
void |
setAccessControlAllowOrigin(String allowedOrigin)
Set the (new) value of the
Access-Control-Allow-Origin response header. |
void |
setAccessControlExposeHeaders(List<String> exposedHeaders)
Set the (new) value of the
Access-Control-Expose-Headers response header. |
void |
setAccessControlMaxAge(Duration maxAge)
Set the (new) value of the
Access-Control-Max-Age response header. |
void |
setAccessControlMaxAge(long maxAge)
Set the (new) value of the
Access-Control-Max-Age response header. |
void |
setAccessControlRequestHeaders(List<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(Map<String,String> values)
Set the given values under.
|
void |
setAllow(Set<HttpMethod> allowedMethods)
Set the set of allowed
HTTP methods ,
as specified by the Allow header. |
void |
setBasicAuth(String encodedCredentials)
Set the value of the Authorization header to
Basic Authentication based on the given encoded credentials.
|
void |
setBasicAuth(String username,
String password)
Set the value of the Authorization header to
Basic Authentication based on the given username and password.
|
void |
setBasicAuth(String username,
String password,
Charset charset)
Set the value of the Authorization header to
Basic Authentication based on the given username and password.
|
void |
setBearerAuth(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(String cacheControl)
Set the (new) value of the
Cache-Control header. |
void |
setConnection(List<String> connection)
Set the (new) value of the
Connection header. |
void |
setConnection(String connection)
Set the (new) value of the
Connection header. |
void |
setContentDisposition(ContentDisposition contentDisposition)
Set the Content-Disposition header.
|
void |
setContentDispositionFormData(String name,
String filename)
Set the
Content-Disposition header when creating a
"multipart/form-data" request. |
void |
setContentLanguage(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(Instant date)
Set the date and time at which the message was created, as specified
by the
Date header. |
void |
setDate(long date)
Set the date and time at which the message was created, as specified
by the
Date header. |
void |
setDate(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 |
setDate(ZonedDateTime date)
Set the date and time at which the message was created, as specified
by the
Date header. |
void |
setETag(String etag)
Set the (new) entity tag of the body, as specified by the
ETag header. |
void |
setExpires(Instant expires)
Set the date and time at which the message is no longer valid,
as specified by the
Expires 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(ZonedDateTime expires)
Set the duration after which the message is no longer valid,
as specified by the
Expires header. |
void |
setHost(InetSocketAddress host)
Set the (new) value of the
Host header. |
void |
setIfMatch(List<String> ifMatchList)
Set the (new) value of the
If-Match header. |
void |
setIfMatch(String ifMatch)
Set the (new) value of the
If-Match header. |
void |
setIfModifiedSince(Instant ifModifiedSince)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
void |
setIfModifiedSince(long ifModifiedSince)
Set the (new) value of the
If-Modified-Since header. |
void |
setIfModifiedSince(ZonedDateTime ifModifiedSince)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
void |
setIfNoneMatch(List<String> ifNoneMatchList)
Set the (new) values of the
If-None-Match header. |
void |
setIfNoneMatch(String ifNoneMatch)
Set the (new) value of the
If-None-Match header. |
void |
setIfUnmodifiedSince(Instant ifUnmodifiedSince)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
void |
setIfUnmodifiedSince(long ifUnmodifiedSince)
Set the (new) value of the
If-Unmodified-Since header. |
void |
setIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
void |
setInstant(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.
|
void |
setLastModified(Instant lastModified)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
void |
setLastModified(long lastModified)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
void |
setLastModified(ZonedDateTime lastModified)
Set the time the resource was last changed, as specified by the
Last-Modified header. |
void |
setLocation(URI location)
Set the (new) location of a resource,
as specified by the
Location header. |
void |
setOrigin(String origin)
Set the (new) value of the
Origin header. |
void |
setPragma(String pragma)
Set the (new) value of the
Pragma header. |
void |
setRange(List<HttpRange> ranges)
Sets the (new) value of the
Range header. |
void |
setUpgrade(String upgrade)
Set the (new) value of the
Upgrade header. |
void |
setVary(List<String> requestHeaders)
Set the request header names (e.g.
|
void |
setZonedDateTime(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.
|
int |
size() |
protected String |
toCommaDelimitedString(List<String> headerValues)
Turn the given list of header values into a comma-delimited result.
|
Map<String,String> |
toSingleValueMap()
Return a
Map with the first values contained in this MultiValueMap . |
String |
toString() |
Collection<List<String>> |
values() |
static HttpHeaders |
writableHttpHeaders(HttpHeaders headers)
Remove any read-only wrapper that may have been previously applied around
the given headers via
readOnlyHttpHeaders(HttpHeaders) . |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
addIfAbsent
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public static final String ACCEPT
Accept
header field name.public static final String ACCEPT_CHARSET
Accept-Charset
header field name.public static final String ACCEPT_ENCODING
Accept-Encoding
header field name.public static final String ACCEPT_LANGUAGE
Accept-Language
header field name.public static final String ACCEPT_PATCH
Accept-Patch
header field name.public static final String ACCEPT_RANGES
Accept-Ranges
header field name.public static final String ACCESS_CONTROL_ALLOW_CREDENTIALS
Access-Control-Allow-Credentials
response header field name.public static final String ACCESS_CONTROL_ALLOW_HEADERS
Access-Control-Allow-Headers
response header field name.public static final String ACCESS_CONTROL_ALLOW_METHODS
Access-Control-Allow-Methods
response header field name.public static final String ACCESS_CONTROL_ALLOW_ORIGIN
Access-Control-Allow-Origin
response header field name.public static final String ACCESS_CONTROL_EXPOSE_HEADERS
Access-Control-Expose-Headers
response header field name.public static final String ACCESS_CONTROL_MAX_AGE
Access-Control-Max-Age
response header field name.public static final String ACCESS_CONTROL_REQUEST_HEADERS
Access-Control-Request-Headers
request header field name.public static final String ACCESS_CONTROL_REQUEST_METHOD
Access-Control-Request-Method
request header field name.public static final String AGE
Age
header field name.public static final String ALLOW
Allow
header field name.public static final String AUTHORIZATION
Authorization
header field name.public static final String CACHE_CONTROL
Cache-Control
header field name.public static final String CONNECTION
Connection
header field name.public static final String CONTENT_ENCODING
Content-Encoding
header field name.public static final String CONTENT_DISPOSITION
Content-Disposition
header field name.public static final String CONTENT_LANGUAGE
Content-Language
header field name.public static final String CONTENT_LENGTH
Content-Length
header field name.public static final String CONTENT_LOCATION
Content-Location
header field name.public static final String CONTENT_RANGE
Content-Range
header field name.public static final String CONTENT_TYPE
Content-Type
header field name.public static final String COOKIE
Cookie
header field name.public static final String DATE
Date
header field name.public static final String ETAG
ETag
header field name.public static final String EXPECT
Expect
header field name.public static final String EXPIRES
Expires
header field name.public static final String FROM
From
header field name.public static final String HOST
Host
header field name.public static final String IF_MATCH
If-Match
header field name.public static final String IF_MODIFIED_SINCE
If-Modified-Since
header field name.public static final String IF_NONE_MATCH
If-None-Match
header field name.public static final String IF_RANGE
If-Range
header field name.public static final String IF_UNMODIFIED_SINCE
If-Unmodified-Since
header field name.public static final String LAST_MODIFIED
Last-Modified
header field name.public static final String LINK
Link
header field name.public static final String LOCATION
Location
header field name.public static final String MAX_FORWARDS
Max-Forwards
header field name.public static final String ORIGIN
Origin
header field name.public static final String PRAGMA
Pragma
header field name.public static final String PROXY_AUTHENTICATE
Proxy-Authenticate
header field name.public static final String PROXY_AUTHORIZATION
Proxy-Authorization
header field name.public static final String RANGE
Range
header field name.public static final String REFERER
Referer
header field name.public static final String RETRY_AFTER
Retry-After
header field name.public static final String SERVER
Server
header field name.public static final String SET_COOKIE
Set-Cookie
header field name.public static final String SET_COOKIE2
Set-Cookie2
header field name.public static final String TE
TE
header field name.public static final String TRAILER
Trailer
header field name.public static final String TRANSFER_ENCODING
Transfer-Encoding
header field name.public static final String UPGRADE
Upgrade
header field name.public static final String USER_AGENT
User-Agent
header field name.public static final String VARY
Vary
header field name.public static final String VIA
Via
header field name.public static final String WARNING
Warning
header field name.public static final String WWW_AUTHENTICATE
WWW-Authenticate
header field name.public static final HttpHeaders EMPTY
HttpHeaders
instance (immutable).public HttpHeaders()
HttpHeaders
object.
This is the common constructor, using a case-insensitive map structure.
public HttpHeaders(MultiValueMap<String,String> headers)
HttpHeaders
instance 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.
headers
- the headers map (expected to operate with case-insensitive keys)public List<String> getOrEmpty(Object headerName)
headerName
- the header namepublic void setAccept(List<MediaType> acceptableMediaTypes)
Accept
header.public List<MediaType> getAccept()
Accept
header.
Returns an empty list when the acceptable media types are unspecified.
public void setAcceptLanguage(List<Locale.LanguageRange> languages)
public List<Locale.LanguageRange> getAcceptLanguage()
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)
.
IllegalArgumentException
- if the value cannot be converted to a language rangepublic void setAcceptLanguageAsLocales(List<Locale> locales)
setAcceptLanguage(List)
using Locale
's.public List<Locale> getAcceptLanguageAsLocales()
IllegalArgumentException
- if the value cannot be converted to a localepublic List<MediaType> getAcceptPatch()
PATCH
methods, as specified by the Accept-Patch
header.
Returns an empty list when the acceptable media types are unspecified.
public void setAccessControlAllowCredentials(boolean allowCredentials)
Access-Control-Allow-Credentials
response header.public boolean getAccessControlAllowCredentials()
Access-Control-Allow-Credentials
response header.public void setAccessControlAllowHeaders(List<String> allowedHeaders)
Access-Control-Allow-Headers
response header.public List<String> getAccessControlAllowHeaders()
Access-Control-Allow-Headers
response header.public void setAccessControlAllowMethods(List<HttpMethod> allowedMethods)
Access-Control-Allow-Methods
response header.public List<HttpMethod> getAccessControlAllowMethods()
Access-Control-Allow-Methods
response header.public void setAccessControlAllowOrigin(@Nullable String allowedOrigin)
Access-Control-Allow-Origin
response header.@Nullable public String getAccessControlAllowOrigin()
Access-Control-Allow-Origin
response header.public void setAccessControlExposeHeaders(List<String> exposedHeaders)
Access-Control-Expose-Headers
response header.public List<String> getAccessControlExposeHeaders()
Access-Control-Expose-Headers
response header.public void setAccessControlMaxAge(Duration maxAge)
Access-Control-Max-Age
response header.public void setAccessControlMaxAge(long maxAge)
Access-Control-Max-Age
response header.public long getAccessControlMaxAge()
Access-Control-Max-Age
response header.
Returns -1 when the max age is unknown.
public void setAccessControlRequestHeaders(List<String> requestHeaders)
Access-Control-Request-Headers
request header.public List<String> getAccessControlRequestHeaders()
Access-Control-Request-Headers
request header.public void setAccessControlRequestMethod(@Nullable HttpMethod requestMethod)
Access-Control-Request-Method
request header.@Nullable public HttpMethod getAccessControlRequestMethod()
Access-Control-Request-Method
request header.public void setAcceptCharset(List<Charset> acceptableCharsets)
Accept-Charset
header.public List<Charset> getAcceptCharset()
Accept-Charset
header.public void setAllow(Set<HttpMethod> allowedMethods)
HTTP methods
,
as specified by the Allow
header.public Set<HttpMethod> getAllow()
HTTP methods
,
as specified by the Allow
header.
Returns an empty set when the allowed methods are unspecified.
public void setBasicAuth(String username, String password)
Note that this method only supports characters in the
ISO-8859-1
character set.
username
- the usernamepassword
- the passwordIllegalArgumentException
- if either user
or
password
contain characters that cannot be encoded to ISO-8859-1setBasicAuth(String)
,
setBasicAuth(String, String, Charset)
,
encodeBasicAuth(String, String, Charset)
,
RFC 7617public void setBasicAuth(String username, String password, @Nullable Charset charset)
username
- the usernamepassword
- the passwordcharset
- the charset to use to convert the credentials into an octet
sequence. Defaults to ISO-8859-1.IllegalArgumentException
- if username
or password
contains characters that cannot be encoded to the given charsetsetBasicAuth(String)
,
setBasicAuth(String, String)
,
encodeBasicAuth(String, String, Charset)
,
RFC 7617public void setBasicAuth(String encodedCredentials)
Favor this method over setBasicAuth(String, String)
and
setBasicAuth(String, String, Charset)
if you wish to cache the
encoded credentials.
encodedCredentials
- the encoded credentialsIllegalArgumentException
- if supplied credentials string is
null
or blanksetBasicAuth(String, String)
,
setBasicAuth(String, String, Charset)
,
encodeBasicAuth(String, String, Charset)
,
RFC 7617public void setBearerAuth(String token)
token
- the Base64 encoded tokenpublic void setCacheControl(CacheControl cacheControl)
CacheControl
instance as the
new value of the Cache-Control
header.public void setCacheControl(@Nullable String cacheControl)
Cache-Control
header.@Nullable public String getCacheControl()
Cache-Control
header.public void setConnection(String connection)
Connection
header.public void setConnection(List<String> connection)
Connection
header.public void setContentDispositionFormData(String name, @Nullable String filename)
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
.
name
- the control namefilename
- the filename (may be null
)getContentDisposition()
public void setContentDisposition(ContentDisposition contentDisposition)
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 on setContentDispositionFormData(java.lang.String, java.lang.String)
.
getContentDisposition()
public ContentDisposition getContentDisposition()
setContentDisposition(ContentDisposition)
public void setContentLanguage(@Nullable Locale locale)
Locale
of the content language,
as specified by the Content-Language header.
Use put(CONTENT_LANGUAGE, list)
if you need
to set multiple content languages.
@Nullable public Locale getContentLanguage()
Locale
of the content languages, as specified by the
Content-Language
header.
Use getValuesAsList(String)
if you need to get multiple content
languages.
Locale
of the content languages, or null
if unknownpublic void setContentLength(long contentLength)
Content-Length
header.public long getContentLength()
Content-Length
header.
Returns -1 when the content-length is unknown.
public void setContentType(@Nullable MediaType mediaType)
Content-Type
header.@Nullable public MediaType getContentType()
Content-Type
header.
Returns null
when the Content-Type
header is not set.
InvalidMediaTypeException
- if the media type value cannot be parsedpublic void setDate(ZonedDateTime date)
Date
header.public void setDate(Instant date)
Date
header.public void setDate(long date)
Date
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
public long getDate()
Date
header.
The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
IllegalArgumentException
- if the value cannot be converted to a datepublic void setETag(@Nullable String etag)
ETag
header.@Nullable public String getETag()
ETag
header.public void setExpires(ZonedDateTime expires)
Expires
header.public void setExpires(Instant expires)
Expires
header.public void setExpires(long expires)
Expires
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
public long getExpires()
Expires
header.
The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
getFirstZonedDateTime(String)
public void setHost(@Nullable InetSocketAddress host)
Host
header.
If the given port is 0
,
the host header will only contain the
host name.
@Nullable public InetSocketAddress getHost()
Host
header, if available.
If the header value does not contain a port, the
port in the returned address will
be 0
.
public void setIfMatch(String ifMatch)
If-Match
header.public void setIfMatch(List<String> ifMatchList)
If-Match
header.public List<String> getIfMatch()
If-Match
header.IllegalArgumentException
- if parsing failspublic void setIfModifiedSince(ZonedDateTime ifModifiedSince)
Last-Modified
header.public void setIfModifiedSince(Instant ifModifiedSince)
Last-Modified
header.public void setIfModifiedSince(long ifModifiedSince)
If-Modified-Since
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
public long getIfModifiedSince()
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.
getFirstZonedDateTime(String)
public void setIfNoneMatch(String ifNoneMatch)
If-None-Match
header.public void setIfNoneMatch(List<String> ifNoneMatchList)
If-None-Match
header.public List<String> getIfNoneMatch()
If-None-Match
header.IllegalArgumentException
- if parsing failspublic void setIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince)
Last-Modified
header.public void setIfUnmodifiedSince(Instant ifUnmodifiedSince)
Last-Modified
header.public void setIfUnmodifiedSince(long ifUnmodifiedSince)
If-Unmodified-Since
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
public long getIfUnmodifiedSince()
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.
getFirstZonedDateTime(String)
public void setLastModified(ZonedDateTime lastModified)
Last-Modified
header.public void setLastModified(Instant lastModified)
Last-Modified
header.public void setLastModified(long lastModified)
Last-Modified
header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
public long getLastModified()
Last-Modified
header.
The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
getFirstZonedDateTime(String)
public void setLocation(@Nullable URI location)
Location
header.@Nullable public URI getLocation()
Location
header.
Returns null
when the location is unknown.
public List<HttpRange> getRange()
Range
header.
Returns an empty list when the range is unknown.
public void setUpgrade(@Nullable String upgrade)
Upgrade
header.public void setVary(List<String> requestHeaders)
requestHeaders
- the request header namespublic List<String> getVary()
public void setZonedDateTime(String headerName, ZonedDateTime date)
set(String, String)
but for date headers.public void setInstant(String headerName, Instant date)
set(String, String)
but for date headers.public void setDate(String headerName, long date)
set(String, String)
but for date headers.setZonedDateTime(String, ZonedDateTime)
public long getFirstDate(String headerName)
IllegalArgumentException
if the value cannot be parsed as a date.headerName
- the header namegetFirstZonedDateTime(String)
@Nullable public ZonedDateTime getFirstZonedDateTime(String headerName)
null
if there is no value, or raise IllegalArgumentException
if the value cannot be parsed as a date.headerName
- the header namenull
if nonepublic List<String> getValuesAsList(String headerName)
headerName
- the header namepublic void clearContentHeaders()
"Content-*"
HTTP headers.
Such headers should be cleared from the response if the intended body can't be written due to errors.
protected List<String> getETagValuesAsList(String name)
name
- the header nameIllegalArgumentException
- if parsing fails@Nullable protected String getFieldValues(String headerName)
headerName
- the header nameprotected String toCommaDelimitedString(List<String> headerValues)
headerValues
- the list of header values@Nullable public String getFirst(String headerName)
getFirst
in interface MultiValueMap<String,String>
headerName
- the header namenull
if nonepublic void add(String headerName, @Nullable String headerValue)
add
in interface MultiValueMap<String,String>
headerName
- the header nameheaderValue
- the header valueUnsupportedOperationException
- if adding headers is not supportedput(String, List)
,
set(String, String)
public void addAll(String key, List<? extends String> values)
MultiValueMap
addAll
in interface MultiValueMap<String,String>
key
- they keyvalues
- the values to be addedpublic void addAll(MultiValueMap<String,String> values)
MultiValueMap
MultiValueMap
to the current values.addAll
in interface MultiValueMap<String,String>
values
- the values to be addedpublic void set(String headerName, @Nullable String headerValue)
set
in interface MultiValueMap<String,String>
headerName
- the header nameheaderValue
- the header valueUnsupportedOperationException
- if adding headers is not supportedput(String, List)
,
add(String, String)
public void setAll(Map<String,String> values)
MultiValueMap
setAll
in interface MultiValueMap<String,String>
values
- the values.public Map<String,String> toSingleValueMap()
MultiValueMap
Map
with the first values contained in this MultiValueMap
.toSingleValueMap
in interface MultiValueMap<String,String>
public boolean containsKey(Object key)
containsKey
in interface Map<String,List<String>>
public boolean containsValue(Object value)
containsValue
in interface Map<String,List<String>>
public Collection<List<String>> values()
public int hashCode()
public static HttpHeaders readOnlyHttpHeaders(MultiValueMap<String,String> headers)
HttpHeaders
wrapper around the given headers, if necessary.
Also caches the parsed representations of the "Accept" and "Content-Type" headers.
headers
- the headers to exposeHttpHeaders
instance already)public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
HttpHeaders
wrapper around the given headers, if necessary.
Also caches the parsed representations of the "Accept" and "Content-Type" headers.
headers
- the headers to exposepublic static HttpHeaders writableHttpHeaders(HttpHeaders headers)
readOnlyHttpHeaders(HttpHeaders)
.headers
- the headers to exposepublic static String formatHeaders(MultiValueMap<String,String> headers)
Map
formatting that also uses commas between entries.headers
- the headers to formatpublic static String encodeBasicAuth(String username, String password, @Nullable Charset charset)
The encoded credentials returned by this method can be supplied to
setBasicAuth(String)
to set the Basic Authentication header.
username
- the usernamepassword
- the passwordcharset
- the charset to use to convert the credentials into an octet
sequence. Defaults to ISO-8859-1.IllegalArgumentException
- if username
or password
contains characters that cannot be encoded to the given charsetsetBasicAuth(String)
,
setBasicAuth(String, String)
,
setBasicAuth(String, String, Charset)
,
RFC 7617