类 HttpHeaders
- java.lang.Object
- org.springframework.http.HttpHeaders
- 所有已实现的接口:
Serializable
,Map<String,List<String>>
,MultiValueMap<String,String>
- 直接已知子类:
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
HttpHeaders
generally treats header names in a case-insensitive manner.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Sebastien Deleuze, Brian Clozel, Juergen Hoeller, Josh Long, Sam Brannen
- 另请参阅:
- 序列化表格
字段概要
字段 修饰符和类型 字段 说明 static String
ACCEPT
The HTTPAccept
header field name.static String
ACCEPT_CHARSET
The HTTPAccept-Charset
header field name.static String
ACCEPT_ENCODING
The HTTPAccept-Encoding
header field name.static String
ACCEPT_LANGUAGE
The HTTPAccept-Language
header field name.static String
ACCEPT_RANGES
The HTTPAccept-Ranges
header field name.static String
ACCESS_CONTROL_ALLOW_CREDENTIALS
The CORSAccess-Control-Allow-Credentials
response header field name.static String
ACCESS_CONTROL_ALLOW_HEADERS
The CORSAccess-Control-Allow-Headers
response header field name.static String
ACCESS_CONTROL_ALLOW_METHODS
The CORSAccess-Control-Allow-Methods
response header field name.static String
ACCESS_CONTROL_ALLOW_ORIGIN
The CORSAccess-Control-Allow-Origin
response header field name.static String
ACCESS_CONTROL_EXPOSE_HEADERS
The CORSAccess-Control-Expose-Headers
response header field name.static String
ACCESS_CONTROL_MAX_AGE
The CORSAccess-Control-Max-Age
response header field name.static String
ACCESS_CONTROL_REQUEST_HEADERS
The CORSAccess-Control-Request-Headers
request header field name.static String
ACCESS_CONTROL_REQUEST_METHOD
The CORSAccess-Control-Request-Method
request header field name.static String
AGE
The HTTPAge
header field name.static String
ALLOW
The HTTPAllow
header field name.static String
AUTHORIZATION
The HTTPAuthorization
header field name.static String
CACHE_CONTROL
The HTTPCache-Control
header field name.static String
CONNECTION
The HTTPConnection
header field name.static String
CONTENT_DISPOSITION
The HTTPContent-Disposition
header field name.static String
CONTENT_ENCODING
The HTTPContent-Encoding
header field name.static String
CONTENT_LANGUAGE
The HTTPContent-Language
header field name.static String
CONTENT_LENGTH
The HTTPContent-Length
header field name.static String
CONTENT_LOCATION
The HTTPContent-Location
header field name.static String
CONTENT_RANGE
The HTTPContent-Range
header field name.static String
CONTENT_TYPE
The HTTPContent-Type
header field name.static String
COOKIE
The HTTPCookie
header field name.static String
DATE
The HTTPDate
header field name.static HttpHeaders
EMPTY
An emptyHttpHeaders
instance (immutable).static String
ETAG
The HTTPETag
header field name.static String
EXPECT
The HTTPExpect
header field name.static String
EXPIRES
The HTTPExpires
header field name.static String
FROM
The HTTPFrom
header field name.static String
HOST
The HTTPHost
header field name.static String
IF_MATCH
The HTTPIf-Match
header field name.static String
IF_MODIFIED_SINCE
The HTTPIf-Modified-Since
header field name.static String
IF_NONE_MATCH
The HTTPIf-None-Match
header field name.static String
IF_RANGE
The HTTPIf-Range
header field name.static String
IF_UNMODIFIED_SINCE
The HTTPIf-Unmodified-Since
header field name.static String
LAST_MODIFIED
The HTTPLast-Modified
header field name.static String
LINK
The HTTPLink
header field name.static String
LOCATION
The HTTPLocation
header field name.static String
MAX_FORWARDS
The HTTPMax-Forwards
header field name.static String
ORIGIN
The HTTPOrigin
header field name.static String
PRAGMA
The HTTPPragma
header field name.static String
PROXY_AUTHENTICATE
The HTTPProxy-Authenticate
header field name.static String
PROXY_AUTHORIZATION
The HTTPProxy-Authorization
header field name.static String
RANGE
The HTTPRange
header field name.static String
REFERER
The HTTPReferer
header field name.static String
RETRY_AFTER
The HTTPRetry-After
header field name.static String
SERVER
The HTTPServer
header field name.static String
SET_COOKIE
The HTTPSet-Cookie
header field name.static String
SET_COOKIE2
The HTTPSet-Cookie2
header field name.static String
TE
The HTTPTE
header field name.static String
TRAILER
The HTTPTrailer
header field name.static String
TRANSFER_ENCODING
The HTTPTransfer-Encoding
header field name.static String
UPGRADE
The HTTPUpgrade
header field name.static String
USER_AGENT
The HTTPUser-Agent
header field name.static String
VARY
The HTTPVary
header field name.static String
VIA
The HTTPVia
header field name.static String
WARNING
The HTTPWarning
header field name.static String
WWW_AUTHENTICATE
The HTTPWWW-Authenticate
header field name.
构造器概要
构造器 构造器 说明 HttpHeaders()
Construct a new, empty instance of theHttpHeaders
object.HttpHeaders(MultiValueMap<String,String> headers)
Construct a newHttpHeaders
instance backed by an existing map.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 void
add(String headerName, String headerValue)
Add the given, single header value under the given name.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
addAll(MultiValueMap<String,String> values)
Add all the values of the givenMultiValueMap
to the current values.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 regularMap
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 theAccept
header.List<Charset>
getAcceptCharset()
Return the list of acceptable charsets, as specified by theAccept-Charset
header.List<Locale.LanguageRange>
getAcceptLanguage()
Return the language ranges from the "Accept-Language" header.List<Locale>
getAcceptLanguageAsLocales()
boolean
getAccessControlAllowCredentials()
Return the value of theAccess-Control-Allow-Credentials
response header.List<String>
getAccessControlAllowHeaders()
Return the value of theAccess-Control-Allow-Headers
response header.List<HttpMethod>
getAccessControlAllowMethods()
Return the value of theAccess-Control-Allow-Methods
response header.String
getAccessControlAllowOrigin()
Return the value of theAccess-Control-Allow-Origin
response header.List<String>
getAccessControlExposeHeaders()
Return the value of theAccess-Control-Expose-Headers
response header.long
getAccessControlMaxAge()
Return the value of theAccess-Control-Max-Age
response header.List<String>
getAccessControlRequestHeaders()
Return the value of theAccess-Control-Request-Headers
request header.HttpMethod
getAccessControlRequestMethod()
Return the value of theAccess-Control-Request-Method
request header.Set<HttpMethod>
getAllow()
Return the set of allowedHTTP methods
, as specified by theAllow
header.String
getCacheControl()
Return the value of theCache-Control
header.List<String>
getConnection()
Return the value of theConnection
header.ContentDisposition
getContentDisposition()
Return a parsed representation of the Content-Disposition header.Locale
getContentLanguage()
Get the firstLocale
of the content languages, as specified by theContent-Language
header.long
getContentLength()
Return the length of the body in bytes, as specified by theContent-Length
header.MediaType
getContentType()
Return the media type of the body, as specified by theContent-Type
header.long
getDate()
Return the date and time at which the message was created, as specified by theDate
header.String
getETag()
Return the entity tag of the body, as specified by theETag
header.protected List<String>
getETagValuesAsList(String headerName)
Retrieve a combined result from the field values of the ETag header.long
getExpires()
Return the date and time at which the message is no longer valid, as specified by theExpires
header.protected String
getFieldValues(String headerName)
Retrieve a combined result from the field values of multi-valued 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 raiseIllegalArgumentException
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, returnnull
if there is no value, or raiseIllegalArgumentException
if the value cannot be parsed as a date.InetSocketAddress
getHost()
Return the value of theHost
header, if available.List<String>
getIfMatch()
Return the value of theIf-Match
header.long
getIfModifiedSince()
Return the value of theIf-Modified-Since
header.List<String>
getIfNoneMatch()
Return the value of theIf-None-Match
header.long
getIfUnmodifiedSince()
Return the value of theIf-Unmodified-Since
header.long
getLastModified()
Return the time the resource was last changed, as specified by theLast-Modified
header.URI
getLocation()
Return the (new) location of a resource as specified by theLocation
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 theOrigin
header.String
getPragma()
Return the value of thePragma
header.List<HttpRange>
getRange()
Return the value of theRange
header.String
getUpgrade()
Return the value of theUpgrade
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-onlyHttpHeaders
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 theAccept
header.void
setAcceptCharset(List<Charset> acceptableCharsets)
Set the list of acceptable charsets, as specified by theAccept-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 ofsetAcceptLanguage(List)
usingLocale
's.void
setAccessControlAllowCredentials(boolean allowCredentials)
Set the (new) value of theAccess-Control-Allow-Credentials
response header.void
setAccessControlAllowHeaders(List<String> allowedHeaders)
Set the (new) value of theAccess-Control-Allow-Headers
response header.void
setAccessControlAllowMethods(List<HttpMethod> allowedMethods)
Set the (new) value of theAccess-Control-Allow-Methods
response header.void
setAccessControlAllowOrigin(String allowedOrigin)
Set the (new) value of theAccess-Control-Allow-Origin
response header.void
setAccessControlExposeHeaders(List<String> exposedHeaders)
Set the (new) value of theAccess-Control-Expose-Headers
response header.void
setAccessControlMaxAge(long maxAge)
Set the (new) value of theAccess-Control-Max-Age
response header.void
setAccessControlMaxAge(Duration maxAge)
Set the (new) value of theAccess-Control-Max-Age
response header.void
setAccessControlRequestHeaders(List<String> requestHeaders)
Set the (new) value of theAccess-Control-Request-Headers
request header.void
setAccessControlRequestMethod(HttpMethod requestMethod)
Set the (new) value of theAccess-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 allowedHTTP methods
, as specified by theAllow
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(String cacheControl)
Set the (new) value of theCache-Control
header.void
setCacheControl(CacheControl cacheControl)
Set a configuredCacheControl
instance as the new value of theCache-Control
header.void
setConnection(String connection)
Set the (new) value of theConnection
header.void
setConnection(List<String> connection)
Set the (new) value of theConnection
header.void
setContentDisposition(ContentDisposition contentDisposition)
Set the Content-Disposition header.void
setContentDispositionFormData(String name, String filename)
Set theContent-Disposition
header when creating a"multipart/form-data"
request.void
setContentLanguage(Locale locale)
Set theLocale
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 theContent-Length
header.void
setContentType(MediaType mediaType)
Set the media type of the body, as specified by theContent-Type
header.void
setDate(long date)
Set the date and time at which the message was created, as specified by theDate
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(Instant date)
Set the date and time at which the message was created, as specified by theDate
header.void
setDate(ZonedDateTime date)
Set the date and time at which the message was created, as specified by theDate
header.void
setETag(String etag)
Set the (new) entity tag of the body, as specified by theETag
header.void
setExpires(long expires)
Set the date and time at which the message is no longer valid, as specified by theExpires
header.void
setExpires(Instant expires)
Set the date and time at which the message is no longer valid, as specified by theExpires
header.void
setExpires(ZonedDateTime expires)
Set the duration after which the message is no longer valid, as specified by theExpires
header.void
setHost(InetSocketAddress host)
Set the (new) value of theHost
header.void
setIfMatch(String ifMatch)
Set the (new) value of theIf-Match
header.void
setIfMatch(List<String> ifMatchList)
Set the (new) value of theIf-Match
header.void
setIfModifiedSince(long ifModifiedSince)
Set the (new) value of theIf-Modified-Since
header.void
setIfModifiedSince(Instant ifModifiedSince)
Set the time the resource was last changed, as specified by theLast-Modified
header.void
setIfModifiedSince(ZonedDateTime ifModifiedSince)
Set the time the resource was last changed, as specified by theLast-Modified
header.void
setIfNoneMatch(String ifNoneMatch)
Set the (new) value of theIf-None-Match
header.void
setIfNoneMatch(List<String> ifNoneMatchList)
Set the (new) values of theIf-None-Match
header.void
setIfUnmodifiedSince(long ifUnmodifiedSince)
Set the (new) value of theIf-Unmodified-Since
header.void
setIfUnmodifiedSince(Instant ifUnmodifiedSince)
Set the time the resource was last changed, as specified by theLast-Modified
header.void
setIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince)
Set the time the resource was last changed, as specified by theLast-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(long lastModified)
Set the time the resource was last changed, as specified by theLast-Modified
header.void
setLastModified(Instant lastModified)
Set the time the resource was last changed, as specified by theLast-Modified
header.void
setLastModified(ZonedDateTime lastModified)
Set the time the resource was last changed, as specified by theLast-Modified
header.void
setLocation(URI location)
Set the (new) location of a resource, as specified by theLocation
header.void
setOrigin(String origin)
Set the (new) value of theOrigin
header.void
setPragma(String pragma)
Set the (new) value of thePragma
header.void
setRange(List<HttpRange> ranges)
Sets the (new) value of theRange
header.void
setUpgrade(String upgrade)
Set the (new) value of theUpgrade
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 aMap
with the first values contained in thisMultiValueMap
.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 viareadOnlyHttpHeaders(HttpHeaders)
.从接口继承的方法 java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
从接口继承的方法 org.springframework.util.MultiValueMap
addIfAbsent
字段详细资料
ACCEPT_CHARSET
public static final String ACCEPT_CHARSET
The HTTPAccept-Charset
header field name.
ACCEPT_ENCODING
public static final String ACCEPT_ENCODING
The HTTPAccept-Encoding
header field name.
ACCEPT_LANGUAGE
public static final String ACCEPT_LANGUAGE
The HTTPAccept-Language
header field name.
ACCEPT_RANGES
public static final String ACCEPT_RANGES
The HTTPAccept-Ranges
header field name.
ACCESS_CONTROL_ALLOW_CREDENTIALS
public static final String ACCESS_CONTROL_ALLOW_CREDENTIALS
The CORSAccess-Control-Allow-Credentials
response header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_ALLOW_HEADERS
public static final String ACCESS_CONTROL_ALLOW_HEADERS
The CORSAccess-Control-Allow-Headers
response header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_ALLOW_METHODS
public static final String ACCESS_CONTROL_ALLOW_METHODS
The CORSAccess-Control-Allow-Methods
response header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_ALLOW_ORIGIN
public static final String ACCESS_CONTROL_ALLOW_ORIGIN
The CORSAccess-Control-Allow-Origin
response header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_EXPOSE_HEADERS
public static final String ACCESS_CONTROL_EXPOSE_HEADERS
The CORSAccess-Control-Expose-Headers
response header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_MAX_AGE
public static final String ACCESS_CONTROL_MAX_AGE
The CORSAccess-Control-Max-Age
response header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_REQUEST_HEADERS
public static final String ACCESS_CONTROL_REQUEST_HEADERS
The CORSAccess-Control-Request-Headers
request header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_REQUEST_METHOD
public static final String ACCESS_CONTROL_REQUEST_METHOD
The CORSAccess-Control-Request-Method
request header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
AGE
public static final String AGE
The HTTPAge
header field name.- 另请参阅:
- Section 5.1 of RFC 7234, 常量字段值
AUTHORIZATION
public static final String AUTHORIZATION
The HTTPAuthorization
header field name.- 另请参阅:
- Section 4.2 of RFC 7235, 常量字段值
CACHE_CONTROL
public static final String CACHE_CONTROL
The HTTPCache-Control
header field name.- 另请参阅:
- Section 5.2 of RFC 7234, 常量字段值
CONNECTION
public static final String CONNECTION
The HTTPConnection
header field name.- 另请参阅:
- Section 6.1 of RFC 7230, 常量字段值
CONTENT_ENCODING
public static final String CONTENT_ENCODING
The HTTPContent-Encoding
header field name.
CONTENT_DISPOSITION
public static final String CONTENT_DISPOSITION
The HTTPContent-Disposition
header field name.
CONTENT_LANGUAGE
public static final String CONTENT_LANGUAGE
The HTTPContent-Language
header field name.
CONTENT_LENGTH
public static final String CONTENT_LENGTH
The HTTPContent-Length
header field name.
CONTENT_LOCATION
public static final String CONTENT_LOCATION
The HTTPContent-Location
header field name.
CONTENT_RANGE
public static final String CONTENT_RANGE
The HTTPContent-Range
header field name.- 另请参阅:
- Section 4.2 of RFC 7233, 常量字段值
CONTENT_TYPE
public static final String CONTENT_TYPE
The HTTPContent-Type
header field name.
ETAG
public static final String ETAG
The HTTPETag
header field name.- 另请参阅:
- Section 2.3 of RFC 7232, 常量字段值
EXPIRES
public static final String EXPIRES
The HTTPExpires
header field name.- 另请参阅:
- Section 5.3 of RFC 7234, 常量字段值
HOST
public static final String HOST
The HTTPHost
header field name.- 另请参阅:
- Section 5.4 of RFC 7230, 常量字段值
IF_MATCH
public static final String IF_MATCH
The HTTPIf-Match
header field name.- 另请参阅:
- Section 3.1 of RFC 7232, 常量字段值
IF_MODIFIED_SINCE
public static final String IF_MODIFIED_SINCE
The HTTPIf-Modified-Since
header field name.- 另请参阅:
- Section 3.3 of RFC 7232, 常量字段值
IF_NONE_MATCH
public static final String IF_NONE_MATCH
The HTTPIf-None-Match
header field name.- 另请参阅:
- Section 3.2 of RFC 7232, 常量字段值
IF_RANGE
public static final String IF_RANGE
The HTTPIf-Range
header field name.- 另请参阅:
- Section 3.2 of RFC 7233, 常量字段值
IF_UNMODIFIED_SINCE
public static final String IF_UNMODIFIED_SINCE
The HTTPIf-Unmodified-Since
header field name.- 另请参阅:
- Section 3.4 of RFC 7232, 常量字段值
LAST_MODIFIED
public static final String LAST_MODIFIED
The HTTPLast-Modified
header field name.- 另请参阅:
- Section 2.2 of RFC 7232, 常量字段值
MAX_FORWARDS
public static final String MAX_FORWARDS
The HTTPMax-Forwards
header field name.
PRAGMA
public static final String PRAGMA
The HTTPPragma
header field name.- 另请参阅:
- Section 5.4 of RFC 7234, 常量字段值
PROXY_AUTHENTICATE
public static final String PROXY_AUTHENTICATE
The HTTPProxy-Authenticate
header field name.- 另请参阅:
- Section 4.3 of RFC 7235, 常量字段值
PROXY_AUTHORIZATION
public static final String PROXY_AUTHORIZATION
The HTTPProxy-Authorization
header field name.- 另请参阅:
- Section 4.4 of RFC 7235, 常量字段值
RANGE
public static final String RANGE
The HTTPRange
header field name.- 另请参阅:
- Section 3.1 of RFC 7233, 常量字段值
RETRY_AFTER
public static final String RETRY_AFTER
The HTTPRetry-After
header field name.
SET_COOKIE
public static final String SET_COOKIE
The HTTPSet-Cookie
header field name.
SET_COOKIE2
public static final String SET_COOKIE2
The HTTPSet-Cookie2
header field name.
TE
public static final String TE
The HTTPTE
header field name.- 另请参阅:
- Section 4.3 of RFC 7230, 常量字段值
TRAILER
public static final String TRAILER
The HTTPTrailer
header field name.- 另请参阅:
- Section 4.4 of RFC 7230, 常量字段值
TRANSFER_ENCODING
public static final String TRANSFER_ENCODING
The HTTPTransfer-Encoding
header field name.
UPGRADE
public static final String UPGRADE
The HTTPUpgrade
header field name.- 另请参阅:
- Section 6.7 of RFC 7230, 常量字段值
USER_AGENT
public static final String USER_AGENT
The HTTPUser-Agent
header field name.
WARNING
public static final String WARNING
The HTTPWarning
header field name.- 另请参阅:
- Section 5.5 of RFC 7234, 常量字段值
WWW_AUTHENTICATE
public static final String WWW_AUTHENTICATE
The HTTPWWW-Authenticate
header field name.- 另请参阅:
- Section 4.1 of RFC 7235, 常量字段值
EMPTY
public static final HttpHeaders EMPTY
An emptyHttpHeaders
instance (immutable).- 从以下版本开始:
- 5.0
构造器详细资料
HttpHeaders
public HttpHeaders()
Construct a new, empty instance of theHttpHeaders
object.This is the common constructor, using a case-insensitive map structure.
HttpHeaders
public HttpHeaders(MultiValueMap<String,String> headers)
Construct a newHttpHeaders
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)- 从以下版本开始:
- 5.1
方法详细资料
getOrEmpty
public List<String> getOrEmpty(Object headerName)
Get the list of header values for the given header name, if any.- 参数:
headerName
- the header name- 返回:
- the list of header values, or an empty list
- 从以下版本开始:
- 5.2
setAccept
public void setAccept(List<MediaType> acceptableMediaTypes)
Set the list of acceptable media types, as specified by theAccept
header.
getAccept
public List<MediaType> getAccept()
Return the list of acceptable media types, as specified by theAccept
header.Returns an empty list when the acceptable media types are unspecified.
setAcceptLanguage
public void setAcceptLanguage(List<Locale.LanguageRange> languages)
Set the acceptable language ranges, as specified by the Accept-Language header.- 从以下版本开始:
- 5.0
getAcceptLanguage
public List<Locale.LanguageRange> getAcceptLanguage()
Return the language ranges from the "Accept-Language" header.If you only need sorted, preferred locales only use
getAcceptLanguageAsLocales()
or if you need to filter based on a list of supported locales you can pass the returned list toLocale.filter(List, Collection)
.- 抛出:
IllegalArgumentException
- if the value cannot be converted to a language range- 从以下版本开始:
- 5.0
setAcceptLanguageAsLocales
public void setAcceptLanguageAsLocales(List<Locale> locales)
Variant ofsetAcceptLanguage(List)
usingLocale
's.- 从以下版本开始:
- 5.0
getAcceptLanguageAsLocales
public List<Locale> getAcceptLanguageAsLocales()
- 返回:
- the locales or an empty list
- 抛出:
IllegalArgumentException
- if the value cannot be converted to a locale- 从以下版本开始:
- 5.0
setAccessControlAllowCredentials
public void setAccessControlAllowCredentials(boolean allowCredentials)
Set the (new) value of theAccess-Control-Allow-Credentials
response header.
getAccessControlAllowCredentials
public boolean getAccessControlAllowCredentials()
Return the value of theAccess-Control-Allow-Credentials
response header.
setAccessControlAllowHeaders
public void setAccessControlAllowHeaders(List<String> allowedHeaders)
Set the (new) value of theAccess-Control-Allow-Headers
response header.
getAccessControlAllowHeaders
public List<String> getAccessControlAllowHeaders()
Return the value of theAccess-Control-Allow-Headers
response header.
setAccessControlAllowMethods
public void setAccessControlAllowMethods(List<HttpMethod> allowedMethods)
Set the (new) value of theAccess-Control-Allow-Methods
response header.
getAccessControlAllowMethods
public List<HttpMethod> getAccessControlAllowMethods()
Return the value of theAccess-Control-Allow-Methods
response header.
setAccessControlAllowOrigin
public void setAccessControlAllowOrigin(@Nullable String allowedOrigin)
Set the (new) value of theAccess-Control-Allow-Origin
response header.
getAccessControlAllowOrigin
@Nullable public String getAccessControlAllowOrigin()
Return the value of theAccess-Control-Allow-Origin
response header.
setAccessControlExposeHeaders
public void setAccessControlExposeHeaders(List<String> exposedHeaders)
Set the (new) value of theAccess-Control-Expose-Headers
response header.
getAccessControlExposeHeaders
public List<String> getAccessControlExposeHeaders()
Return the value of theAccess-Control-Expose-Headers
response header.
setAccessControlMaxAge
public void setAccessControlMaxAge(Duration maxAge)
Set the (new) value of theAccess-Control-Max-Age
response header.- 从以下版本开始:
- 5.2
setAccessControlMaxAge
public void setAccessControlMaxAge(long maxAge)
Set the (new) value of theAccess-Control-Max-Age
response header.
getAccessControlMaxAge
public long getAccessControlMaxAge()
Return the value of theAccess-Control-Max-Age
response header.Returns -1 when the max age is unknown.
setAccessControlRequestHeaders
public void setAccessControlRequestHeaders(List<String> requestHeaders)
Set the (new) value of theAccess-Control-Request-Headers
request header.
getAccessControlRequestHeaders
public List<String> getAccessControlRequestHeaders()
Return the value of theAccess-Control-Request-Headers
request header.
setAccessControlRequestMethod
public void setAccessControlRequestMethod(@Nullable HttpMethod requestMethod)
Set the (new) value of theAccess-Control-Request-Method
request header.
getAccessControlRequestMethod
@Nullable public HttpMethod getAccessControlRequestMethod()
Return the value of theAccess-Control-Request-Method
request header.
setAcceptCharset
public void setAcceptCharset(List<Charset> acceptableCharsets)
Set the list of acceptable charsets, as specified by theAccept-Charset
header.
getAcceptCharset
public List<Charset> getAcceptCharset()
Return the list of acceptable charsets, as specified by theAccept-Charset
header.
setAllow
public void setAllow(Set<HttpMethod> allowedMethods)
Set the set of allowedHTTP methods
, as specified by theAllow
header.
getAllow
public Set<HttpMethod> getAllow()
Return the set of allowedHTTP methods
, as specified by theAllow
header.Returns an empty set when the allowed methods are unspecified.
setBasicAuth
public void setBasicAuth(String username, String password)
Set 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-1
character set.- 参数:
username
- the usernamepassword
- the password- 抛出:
IllegalArgumentException
- if eitheruser
orpassword
contain characters that cannot be encoded to ISO-8859-1- 从以下版本开始:
- 5.1
- 另请参阅:
setBasicAuth(String)
,setBasicAuth(String, String, Charset)
,encodeBasicAuth(String, String, Charset)
, RFC 7617
setBasicAuth
public void setBasicAuth(String username, String password, @Nullable Charset charset)
Set the value of the Authorization header to Basic Authentication based on the given username and password.- 参数:
username
- the usernamepassword
- the passwordcharset
- the charset to use to convert the credentials into an octet sequence. Defaults to ISO-8859-1.- 抛出:
IllegalArgumentException
- ifusername
orpassword
contains characters that cannot be encoded to the given charset- 从以下版本开始:
- 5.1
- 另请参阅:
setBasicAuth(String)
,setBasicAuth(String, String)
,encodeBasicAuth(String, String, Charset)
, RFC 7617
setBasicAuth
public void setBasicAuth(String encodedCredentials)
Set 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.- 参数:
encodedCredentials
- the encoded credentials- 抛出:
IllegalArgumentException
- if supplied credentials string isnull
or blank- 从以下版本开始:
- 5.2
- 另请参阅:
setBasicAuth(String, String)
,setBasicAuth(String, String, Charset)
,encodeBasicAuth(String, String, Charset)
, RFC 7617
setBearerAuth
public void setBearerAuth(String token)
Set the value of the Authorization header to the given Bearer token.- 参数:
token
- the Base64 encoded token- 从以下版本开始:
- 5.1
- 另请参阅:
- RFC 6750
setCacheControl
public void setCacheControl(CacheControl cacheControl)
Set a configuredCacheControl
instance as the new value of theCache-Control
header.- 从以下版本开始:
- 5.0.5
setCacheControl
public void setCacheControl(@Nullable String cacheControl)
Set the (new) value of theCache-Control
header.
getCacheControl
@Nullable public String getCacheControl()
Return the value of theCache-Control
header.
setConnection
public void setConnection(String connection)
Set the (new) value of theConnection
header.
setConnection
public void setConnection(List<String> connection)
Set the (new) value of theConnection
header.
getConnection
public List<String> getConnection()
Return the value of theConnection
header.
setContentDispositionFormData
public void setContentDispositionFormData(String name, @Nullable String filename)
Set theContent-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 aResource
for each part, and then pass that to theRestTemplate
orWebClient
.- 参数:
name
- the control namefilename
- the filename (may benull
)- 另请参阅:
getContentDisposition()
setContentDisposition
public void setContentDisposition(ContentDisposition contentDisposition)
Set 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)
.- 从以下版本开始:
- 5.0
- 另请参阅:
getContentDisposition()
getContentDisposition
public ContentDisposition getContentDisposition()
Return a parsed representation of the Content-Disposition header.- 从以下版本开始:
- 5.0
- 另请参阅:
setContentDisposition(ContentDisposition)
setContentLanguage
public void setContentLanguage(@Nullable Locale locale)
Set theLocale
of the content language, as specified by the Content-Language header.Use
put(CONTENT_LANGUAGE, list)
if you need to set multiple content languages.- 从以下版本开始:
- 5.0
getContentLanguage
@Nullable public Locale getContentLanguage()
Get the firstLocale
of the content languages, as specified by theContent-Language
header.Use
getValuesAsList(String)
if you need to get multiple content languages.- 返回:
- the first
Locale
of the content languages, ornull
if unknown - 从以下版本开始:
- 5.0
setContentLength
public void setContentLength(long contentLength)
Set the length of the body in bytes, as specified by theContent-Length
header.
getContentLength
public long getContentLength()
Return the length of the body in bytes, as specified by theContent-Length
header.Returns -1 when the content-length is unknown.
setContentType
public void setContentType(@Nullable MediaType mediaType)
Set the media type of the body, as specified by theContent-Type
header.
getContentType
@Nullable public MediaType getContentType()
Return the media type of the body, as specified by theContent-Type
header.Returns
null
when the content-type is unknown.
setDate
public void setDate(ZonedDateTime date)
Set the date and time at which the message was created, as specified by theDate
header.- 从以下版本开始:
- 5.2
setDate
public void setDate(Instant date)
Set the date and time at which the message was created, as specified by theDate
header.- 从以下版本开始:
- 5.2
setDate
public void setDate(long date)
Set the date and time at which the message was created, as specified by theDate
header.The date should be specified as the number of milliseconds since January 1, 1970 GMT.
getDate
public long getDate()
Return the date and time at which the message was created, as specified by theDate
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 date
setETag
public void setETag(@Nullable String etag)
Set the (new) entity tag of the body, as specified by theETag
header.
getETag
@Nullable public String getETag()
Return the entity tag of the body, as specified by theETag
header.
setExpires
public void setExpires(ZonedDateTime expires)
Set the duration after which the message is no longer valid, as specified by theExpires
header.- 从以下版本开始:
- 5.0.5
setExpires
public void setExpires(Instant expires)
Set the date and time at which the message is no longer valid, as specified by theExpires
header.- 从以下版本开始:
- 5.2
setExpires
public void setExpires(long expires)
Set the date and time at which the message is no longer valid, as specified by theExpires
header.The date should be specified as the number of milliseconds since January 1, 1970 GMT.
getExpires
public long getExpires()
Return the date and time at which the message is no longer valid, as specified by theExpires
header.The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
setHost
public void setHost(@Nullable InetSocketAddress host)
Set the (new) value of theHost
header.If the given port is
0
, the host header will only contain the host name.- 从以下版本开始:
- 5.0
getHost
@Nullable public InetSocketAddress getHost()
Return the value of theHost
header, if available.If the header value does not contain a port, the port in the returned address will be
0
.- 从以下版本开始:
- 5.0
setIfMatch
public void setIfMatch(String ifMatch)
Set the (new) value of theIf-Match
header.- 从以下版本开始:
- 4.3
setIfMatch
public void setIfMatch(List<String> ifMatchList)
Set the (new) value of theIf-Match
header.- 从以下版本开始:
- 4.3
getIfMatch
public List<String> getIfMatch()
Return the value of theIf-Match
header.- 抛出:
IllegalArgumentException
- if parsing fails- 从以下版本开始:
- 4.3
setIfModifiedSince
public void setIfModifiedSince(ZonedDateTime ifModifiedSince)
Set the time the resource was last changed, as specified by theLast-Modified
header.- 从以下版本开始:
- 5.1.4
setIfModifiedSince
public void setIfModifiedSince(Instant ifModifiedSince)
Set the time the resource was last changed, as specified by theLast-Modified
header.- 从以下版本开始:
- 5.1.4
setIfModifiedSince
public void setIfModifiedSince(long ifModifiedSince)
Set the (new) value of theIf-Modified-Since
header.The date should be specified as the number of milliseconds since January 1, 1970 GMT.
getIfModifiedSince
public long getIfModifiedSince()
Return the value of theIf-Modified-Since
header.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-Match
header.
setIfNoneMatch
public void setIfNoneMatch(List<String> ifNoneMatchList)
Set the (new) values of theIf-None-Match
header.
getIfNoneMatch
public List<String> getIfNoneMatch()
Return the value of theIf-None-Match
header.- 抛出:
IllegalArgumentException
- if parsing fails
setIfUnmodifiedSince
public void setIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince)
Set the time the resource was last changed, as specified by theLast-Modified
header.- 从以下版本开始:
- 5.1.4
setIfUnmodifiedSince
public void setIfUnmodifiedSince(Instant ifUnmodifiedSince)
Set the time the resource was last changed, as specified by theLast-Modified
header.- 从以下版本开始:
- 5.1.4
setIfUnmodifiedSince
public void setIfUnmodifiedSince(long ifUnmodifiedSince)
Set the (new) value of theIf-Unmodified-Since
header.The date should be specified as the number of milliseconds since January 1, 1970 GMT.
- 从以下版本开始:
- 4.3
getIfUnmodifiedSince
public long getIfUnmodifiedSince()
Return the value of theIf-Unmodified-Since
header.The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
- 从以下版本开始:
- 4.3
- 另请参阅:
getFirstZonedDateTime(String)
setLastModified
public void setLastModified(ZonedDateTime lastModified)
Set the time the resource was last changed, as specified by theLast-Modified
header.- 从以下版本开始:
- 5.1.4
setLastModified
public void setLastModified(Instant lastModified)
Set the time the resource was last changed, as specified by theLast-Modified
header.- 从以下版本开始:
- 5.1.4
setLastModified
public void setLastModified(long lastModified)
Set the time the resource was last changed, as specified by theLast-Modified
header.The date should be specified as the number of milliseconds since January 1, 1970 GMT.
getLastModified
public long getLastModified()
Return the time the resource was last changed, as specified by theLast-Modified
header.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(@Nullable URI location)
Set the (new) location of a resource, as specified by theLocation
header.
getLocation
@Nullable public URI getLocation()
Return the (new) location of a resource as specified by theLocation
header.Returns
null
when the location is unknown.
getRange
public List<HttpRange> getRange()
Return the value of theRange
header.Returns an empty list when the range is unknown.
setUpgrade
public void setUpgrade(@Nullable String upgrade)
Set the (new) value of theUpgrade
header.
getUpgrade
@Nullable public String getUpgrade()
Return the value of theUpgrade
header.
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.- 参数:
requestHeaders
- the request header names- 从以下版本开始:
- 4.3
getVary
public List<String> getVary()
Return the request header names subject to content negotiation.- 从以下版本开始:
- 4.3
setZonedDateTime
public 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. The equivalent ofset(String, String)
but for date headers.- 从以下版本开始:
- 5.0
setInstant
public 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. The equivalent ofset(String, String)
but for date headers.- 从以下版本开始:
- 5.1.4
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 RFC-1123 date-time formatter. The equivalent ofset(String, String)
but for date headers.- 从以下版本开始:
- 3.2.4
- 另请参阅:
setZonedDateTime(String, ZonedDateTime)
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 raiseIllegalArgumentException
if the value cannot be parsed as a date.- 参数:
headerName
- the header name- 返回:
- the parsed date header, or -1 if none
- 从以下版本开始:
- 3.2.4
- 另请参阅:
getFirstZonedDateTime(String)
getFirstZonedDateTime
@Nullable public ZonedDateTime getFirstZonedDateTime(String headerName)
Parse the first header value for the given header name as a date, returnnull
if there is no value, or raiseIllegalArgumentException
if the value cannot be parsed as a date.- 参数:
headerName
- the header name- 返回:
- the parsed date header, or
null
if none - 从以下版本开始:
- 5.0
getValuesAsList
public List<String> getValuesAsList(String headerName)
Return all values of a given header name, even if this header is set multiple times.- 参数:
headerName
- the header name- 返回:
- all associated values
- 从以下版本开始:
- 4.3
clearContentHeaders
public 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.
- 从以下版本开始:
- 5.2.3
getETagValuesAsList
protected List<String> getETagValuesAsList(String headerName)
Retrieve a combined result from the field values of the ETag header.- 参数:
headerName
- the header name- 返回:
- the combined result
- 抛出:
IllegalArgumentException
- if parsing fails- 从以下版本开始:
- 4.3
getFieldValues
@Nullable protected String getFieldValues(String headerName)
Retrieve a combined result from the field values of multi-valued headers.- 参数:
headerName
- the header name- 返回:
- the combined result
- 从以下版本开始:
- 4.3
toCommaDelimitedString
protected String toCommaDelimitedString(List<String> headerValues)
Turn the given list of header values into a comma-delimited result.- 参数:
headerValues
- the list of header values- 返回:
- a combined result with comma delimitation
getFirst
@Nullable public String getFirst(String headerName)
Return the first header value for the given header name, if any.- 指定者:
getFirst
在接口中MultiValueMap<String,String>
- 参数:
headerName
- the header name- 返回:
- the first header value, or
null
if none
add
public void add(String headerName, @Nullable String headerValue)
Add the given, single header value under the given name.- 指定者:
add
在接口中MultiValueMap<String,String>
- 参数:
headerName
- the header nameheaderValue
- the header value- 抛出:
UnsupportedOperationException
- if adding headers is not supported- 另请参阅:
put(String, List)
,set(String, String)
addAll
public void addAll(String key, List<? extends String> values)
从接口复制的说明:MultiValueMap
Add all the values of the given list to the current list of values for the given key.- 指定者:
addAll
在接口中MultiValueMap<String,String>
- 参数:
key
- they keyvalues
- the values to be added
addAll
public void addAll(MultiValueMap<String,String> values)
从接口复制的说明:MultiValueMap
Add all the values of the givenMultiValueMap
to the current values.- 指定者:
addAll
在接口中MultiValueMap<String,String>
- 参数:
values
- the values to be added
set
public void set(String headerName, @Nullable String headerValue)
Set the given, single header value under the given name.- 指定者:
set
在接口中MultiValueMap<String,String>
- 参数:
headerName
- the header nameheaderValue
- the header value- 抛出:
UnsupportedOperationException
- if adding headers is not supported- 另请参阅:
put(String, List)
,add(String, String)
setAll
public void setAll(Map<String,String> values)
从接口复制的说明:MultiValueMap
Set the given values under.- 指定者:
setAll
在接口中MultiValueMap<String,String>
- 参数:
values
- the values.
toSingleValueMap
public Map<String,String> toSingleValueMap()
从接口复制的说明:MultiValueMap
Return aMap
with the first values contained in thisMultiValueMap
.- 指定者:
toSingleValueMap
在接口中MultiValueMap<String,String>
- 返回:
- a single value representation of this map
containsKey
public boolean containsKey(Object key)
- 指定者:
containsKey
在接口中Map<String,List<String>>
containsValue
public boolean containsValue(Object value)
- 指定者:
containsValue
在接口中Map<String,List<String>>
readOnlyHttpHeaders
public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
Apply a read-onlyHttpHeaders
wrapper around the given headers, if necessary.- 参数:
headers
- the headers to expose- 返回:
- a read-only variant of the headers, or the original headers as-is
writableHttpHeaders
public static HttpHeaders writableHttpHeaders(HttpHeaders headers)
Remove any read-only wrapper that may have been previously applied around the given headers viareadOnlyHttpHeaders(HttpHeaders)
.- 参数:
headers
- the headers to expose- 返回:
- a writable variant of the headers, or the original headers as-is
- 从以下版本开始:
- 5.1.1
formatHeaders
public 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 regularMap
formatting that also uses commas between entries.- 参数:
headers
- the headers to format- 返回:
- the headers to a String
- 从以下版本开始:
- 5.1.4
encodeBasicAuth
public static String encodeBasicAuth(String username, String password, @Nullable Charset charset)
Encode 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.- 参数:
username
- the usernamepassword
- the passwordcharset
- the charset to use to convert the credentials into an octet sequence. Defaults to ISO-8859-1.- 抛出:
IllegalArgumentException
- ifusername
orpassword
contains characters that cannot be encoded to the given charset- 从以下版本开始:
- 5.2
- 另请参阅:
setBasicAuth(String)
,setBasicAuth(String, String)
,setBasicAuth(String, String, Charset)
, RFC 7617