类 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
HttpHeadersgenerally treats header names in a case-insensitive manner.- 从以下版本开始:
- 3.0
- 作者:
- Arjen Poutsma, Sebastien Deleuze, Brian Clozel, Juergen Hoeller, Josh Long, Sam Brannen
- 另请参阅:
- 序列化表格
字段概要
字段 修饰符和类型 字段 说明 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 HttpHeadersEMPTYAn emptyHttpHeadersinstance (immutable).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.
构造器概要
构造器 构造器 说明 HttpHeaders()Construct a new, empty instance of theHttpHeadersobject.HttpHeaders(MultiValueMap<String,String> headers)Construct a newHttpHeadersinstance backed by an existing map.
方法概要
所有方法 静态方法 实例方法 具体方法 修饰符和类型 方法 说明 voidadd(String headerName, String headerValue)Add the given, single header value under the given name.voidaddAll(String key, List<? extends String> values)Add all the values of the given list to the current list of values for the given key.voidaddAll(MultiValueMap<String,String> values)Add all the values of the givenMultiValueMapto the current values.voidclear()voidclearContentHeaders()Remove the well-known"Content-*"HTTP headers.booleancontainsKey(Object key)booleancontainsValue(Object value)static StringencodeBasicAuth(String username, String password, Charset charset)Encode the given username and password into Basic Authentication credentials.Set<Map.Entry<String,List<String>>>entrySet()booleanequals(Object other)static StringformatHeaders(MultiValueMap<String,String> headers)Helps to format HTTP header values, as HTTP header values themselves can contain comma-separated values, can become confusing with regularMapformatting that also uses commas between entries.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.List<Locale.LanguageRange>getAcceptLanguage()Return the language ranges from the "Accept-Language" header.List<Locale>getAcceptLanguageAsLocales()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.ContentDispositiongetContentDisposition()Return a parsed representation of the Content-Disposition header.LocalegetContentLanguage()Get the firstLocaleof the content languages, as specified by theContent-Languageheader.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.ZonedDateTimegetFirstZonedDateTime(String headerName)Parse the first header value for the given header name as a date, returnnullif there is no value, or raiseIllegalArgumentExceptionif the value cannot be parsed as a date.InetSocketAddressgetHost()Return the value of theHostheader, if available.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.List<String>getOrEmpty(Object headerName)Get the list of header values for the given header name, if any.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)Apply a read-onlyHttpHeaderswrapper around the given headers, if necessary.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.voidsetAcceptLanguage(List<Locale.LanguageRange> languages)Set the acceptable language ranges, as specified by the Accept-Language header.voidsetAcceptLanguageAsLocales(List<Locale> locales)Variant ofsetAcceptLanguage(List)usingLocale's.voidsetAccessControlAllowCredentials(boolean allowCredentials)Set the (new) value of theAccess-Control-Allow-Credentialsresponse header.voidsetAccessControlAllowHeaders(List<String> allowedHeaders)Set the (new) value of theAccess-Control-Allow-Headersresponse header.voidsetAccessControlAllowMethods(List<HttpMethod> allowedMethods)Set the (new) value of theAccess-Control-Allow-Methodsresponse header.voidsetAccessControlAllowOrigin(String allowedOrigin)Set the (new) value of theAccess-Control-Allow-Originresponse header.voidsetAccessControlExposeHeaders(List<String> exposedHeaders)Set the (new) value of theAccess-Control-Expose-Headersresponse header.voidsetAccessControlMaxAge(long maxAge)Set the (new) value of theAccess-Control-Max-Ageresponse header.voidsetAccessControlMaxAge(Duration maxAge)Set the (new) value of theAccess-Control-Max-Ageresponse header.voidsetAccessControlRequestHeaders(List<String> requestHeaders)Set the (new) value of theAccess-Control-Request-Headersrequest header.voidsetAccessControlRequestMethod(HttpMethod requestMethod)Set the (new) value of theAccess-Control-Request-Methodrequest header.voidsetAll(Map<String,String> values)Set the given values under.voidsetAllow(Set<HttpMethod> allowedMethods)Set the set of allowedHTTP methods, as specified by theAllowheader.voidsetBasicAuth(String encodedCredentials)Set the value of the Authorization header to Basic Authentication based on the given encoded credentials.voidsetBasicAuth(String username, String password)Set the value of the Authorization header to Basic Authentication based on the given username and password.voidsetBasicAuth(String username, String password, Charset charset)Set the value of the Authorization header to Basic Authentication based on the given username and password.voidsetBearerAuth(String token)Set the value of the Authorization header to the given Bearer token.voidsetCacheControl(String cacheControl)Set the (new) value of theCache-Controlheader.voidsetCacheControl(CacheControl cacheControl)Set a configuredCacheControlinstance as the new value of theCache-Controlheader.voidsetConnection(String connection)Set the (new) value of theConnectionheader.voidsetConnection(List<String> connection)Set the (new) value of theConnectionheader.voidsetContentDisposition(ContentDisposition contentDisposition)Set the Content-Disposition header.voidsetContentDispositionFormData(String name, String filename)Set theContent-Dispositionheader when creating a"multipart/form-data"request.voidsetContentLanguage(Locale locale)Set theLocaleof the content language, as specified by the Content-Language header.voidsetContentLength(long contentLength)Set the length of the body in bytes, as specified by theContent-Lengthheader.voidsetContentType(MediaType mediaType)Set the media type of the body, as specified by theContent-Typeheader.voidsetDate(long date)Set the date and time at which the message was created, as specified by theDateheader.voidsetDate(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.voidsetDate(Instant date)Set the date and time at which the message was created, as specified by theDateheader.voidsetDate(ZonedDateTime date)Set the date and time at which the message was created, as specified by theDateheader.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.voidsetExpires(Instant expires)Set the date and time at which the message is no longer valid, as specified by theExpiresheader.voidsetExpires(ZonedDateTime expires)Set the duration after which the message is no longer valid, as specified by theExpiresheader.voidsetHost(InetSocketAddress host)Set the (new) value of theHostheader.voidsetIfMatch(String ifMatch)Set the (new) value of theIf-Matchheader.voidsetIfMatch(List<String> ifMatchList)Set the (new) value of theIf-Matchheader.voidsetIfModifiedSince(long ifModifiedSince)Set the (new) value of theIf-Modified-Sinceheader.voidsetIfModifiedSince(Instant ifModifiedSince)Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetIfModifiedSince(ZonedDateTime ifModifiedSince)Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetIfNoneMatch(String ifNoneMatch)Set the (new) value of theIf-None-Matchheader.voidsetIfNoneMatch(List<String> ifNoneMatchList)Set the (new) values of theIf-None-Matchheader.voidsetIfUnmodifiedSince(long ifUnmodifiedSince)Set the (new) value of theIf-Unmodified-Sinceheader.voidsetIfUnmodifiedSince(Instant ifUnmodifiedSince)Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince)Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetInstant(String headerName, Instant date)Set the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter.voidsetLastModified(long lastModified)Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetLastModified(Instant lastModified)Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetLastModified(ZonedDateTime lastModified)Set the time the resource was last changed, as specified by theLast-Modifiedheader.voidsetLocation(URI location)Set the (new) location of a resource, as specified by theLocationheader.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.voidsetZonedDateTime(String headerName, ZonedDateTime date)Set the given date under the given header name after formatting it as a string using the RFC-1123 date-time formatter.intsize()protected StringtoCommaDelimitedString(List<String> headerValues)Turn the given list of header values into a comma-delimited result.Map<String,String>toSingleValueMap()Return aMapwith the first values contained in thisMultiValueMap.StringtoString()Collection<List<String>>values()static HttpHeaderswritableHttpHeaders(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-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.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_ALLOW_HEADERS
public static final String ACCESS_CONTROL_ALLOW_HEADERS
The CORSAccess-Control-Allow-Headersresponse header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_ALLOW_METHODS
public static final String ACCESS_CONTROL_ALLOW_METHODS
The CORSAccess-Control-Allow-Methodsresponse header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_ALLOW_ORIGIN
public static final String ACCESS_CONTROL_ALLOW_ORIGIN
The CORSAccess-Control-Allow-Originresponse header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_EXPOSE_HEADERS
public static final String ACCESS_CONTROL_EXPOSE_HEADERS
The CORSAccess-Control-Expose-Headersresponse header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_MAX_AGE
public static final String ACCESS_CONTROL_MAX_AGE
The CORSAccess-Control-Max-Ageresponse header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_REQUEST_HEADERS
public static final String ACCESS_CONTROL_REQUEST_HEADERS
The CORSAccess-Control-Request-Headersrequest header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
ACCESS_CONTROL_REQUEST_METHOD
public static final String ACCESS_CONTROL_REQUEST_METHOD
The CORSAccess-Control-Request-Methodrequest header field name.- 另请参阅:
- CORS W3C recommendation, 常量字段值
AGE
public static final String AGE
The HTTPAgeheader field name.- 另请参阅:
- Section 5.1 of RFC 7234, 常量字段值
AUTHORIZATION
public static final String AUTHORIZATION
The HTTPAuthorizationheader field name.- 另请参阅:
- Section 4.2 of RFC 7235, 常量字段值
CACHE_CONTROL
public static final String CACHE_CONTROL
The HTTPCache-Controlheader field name.- 另请参阅:
- Section 5.2 of RFC 7234, 常量字段值
CONNECTION
public static final String CONNECTION
The HTTPConnectionheader field name.- 另请参阅:
- Section 6.1 of RFC 7230, 常量字段值
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.
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.- 另请参阅:
- Section 4.2 of RFC 7233, 常量字段值
CONTENT_TYPE
public static final String CONTENT_TYPE
The HTTPContent-Typeheader field name.
ETAG
public static final String ETAG
The HTTPETagheader field name.- 另请参阅:
- Section 2.3 of RFC 7232, 常量字段值
EXPIRES
public static final String EXPIRES
The HTTPExpiresheader field name.- 另请参阅:
- Section 5.3 of RFC 7234, 常量字段值
HOST
public static final String HOST
The HTTPHostheader field name.- 另请参阅:
- Section 5.4 of RFC 7230, 常量字段值
IF_MATCH
public static final String IF_MATCH
The HTTPIf-Matchheader field name.- 另请参阅:
- Section 3.1 of RFC 7232, 常量字段值
IF_MODIFIED_SINCE
public static final String IF_MODIFIED_SINCE
The HTTPIf-Modified-Sinceheader field name.- 另请参阅:
- Section 3.3 of RFC 7232, 常量字段值
IF_NONE_MATCH
public static final String IF_NONE_MATCH
The HTTPIf-None-Matchheader field name.- 另请参阅:
- Section 3.2 of RFC 7232, 常量字段值
IF_RANGE
public static final String IF_RANGE
The HTTPIf-Rangeheader field name.- 另请参阅:
- Section 3.2 of RFC 7233, 常量字段值
IF_UNMODIFIED_SINCE
public static final String IF_UNMODIFIED_SINCE
The HTTPIf-Unmodified-Sinceheader field name.- 另请参阅:
- Section 3.4 of RFC 7232, 常量字段值
LAST_MODIFIED
public static final String LAST_MODIFIED
The HTTPLast-Modifiedheader field name.- 另请参阅:
- Section 2.2 of RFC 7232, 常量字段值
MAX_FORWARDS
public static final String MAX_FORWARDS
The HTTPMax-Forwardsheader field name.
PRAGMA
public static final String PRAGMA
The HTTPPragmaheader field name.- 另请参阅:
- Section 5.4 of RFC 7234, 常量字段值
PROXY_AUTHENTICATE
public static final String PROXY_AUTHENTICATE
The HTTPProxy-Authenticateheader field name.- 另请参阅:
- Section 4.3 of RFC 7235, 常量字段值
PROXY_AUTHORIZATION
public static final String PROXY_AUTHORIZATION
The HTTPProxy-Authorizationheader field name.- 另请参阅:
- Section 4.4 of RFC 7235, 常量字段值
RANGE
public static final String RANGE
The HTTPRangeheader field name.- 另请参阅:
- Section 3.1 of RFC 7233, 常量字段值
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.
TE
public static final String TE
The HTTPTEheader field name.- 另请参阅:
- Section 4.3 of RFC 7230, 常量字段值
TRAILER
public static final String TRAILER
The HTTPTrailerheader field name.- 另请参阅:
- Section 4.4 of RFC 7230, 常量字段值
TRANSFER_ENCODING
public static final String TRANSFER_ENCODING
The HTTPTransfer-Encodingheader field name.
UPGRADE
public static final String UPGRADE
The HTTPUpgradeheader field name.- 另请参阅:
- Section 6.7 of RFC 7230, 常量字段值
USER_AGENT
public static final String USER_AGENT
The HTTPUser-Agentheader field name.
WARNING
public static final String WARNING
The HTTPWarningheader field name.- 另请参阅:
- Section 5.5 of RFC 7234, 常量字段值
WWW_AUTHENTICATE
public static final String WWW_AUTHENTICATE
The HTTPWWW-Authenticateheader field name.- 另请参阅:
- Section 4.1 of RFC 7235, 常量字段值
EMPTY
public static final HttpHeaders EMPTY
An emptyHttpHeadersinstance (immutable).- 从以下版本开始:
- 5.0
构造器详细资料
HttpHeaders
public HttpHeaders()
Construct a new, empty instance of theHttpHeadersobject.This is the common constructor, using a case-insensitive map structure.
HttpHeaders
public HttpHeaders(MultiValueMap<String,String> headers)
Construct a newHttpHeadersinstance backed by an existing map.This constructor is available as an optimization for adapting to existing headers map structures, primarily for internal use within the framework.
- 参数:
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 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.
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-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(@Nullable String allowedOrigin)
Set the (new) value of theAccess-Control-Allow-Originresponse header.
getAccessControlAllowOrigin
@Nullable 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(Duration maxAge)
Set the (new) value of theAccess-Control-Max-Ageresponse header.- 从以下版本开始:
- 5.2
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(@Nullable HttpMethod requestMethod)
Set the (new) value of theAccess-Control-Request-Methodrequest header.
getAccessControlRequestMethod
@Nullable 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.
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-1character set.- 参数:
username- the usernamepassword- the password- 抛出:
IllegalArgumentException- if eitheruserorpasswordcontain 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- ifusernameorpasswordcontains 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 isnullor 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 configuredCacheControlinstance as the new value of theCache-Controlheader.- 从以下版本开始:
- 5.0.5
setCacheControl
public void setCacheControl(@Nullable String cacheControl)
Set the (new) value of theCache-Controlheader.
getCacheControl
@Nullable 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, @Nullable String filename)
Set theContent-Dispositionheader when creating a"multipart/form-data"request.Applications typically would not set this header directly but rather prepare a
MultiValueMap<String, Object>, containing an Object or aResourcefor each part, and then pass that to theRestTemplateorWebClient.- 参数:
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 theLocaleof 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 firstLocaleof the content languages, as specified by theContent-Languageheader.Use
getValuesAsList(String)if you need to get multiple content languages.- 返回:
- the first
Localeof the content languages, ornullif unknown - 从以下版本开始:
- 5.0
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(@Nullable MediaType mediaType)
Set the media type of the body, as specified by theContent-Typeheader.
getContentType
@Nullable 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(ZonedDateTime date)
Set the date and time at which the message was created, as specified by theDateheader.- 从以下版本开始:
- 5.2
setDate
public void setDate(Instant date)
Set the date and time at which the message was created, as specified by theDateheader.- 从以下版本开始:
- 5.2
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.
- 抛出:
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 theETagheader.
getETag
@Nullable public String getETag()
Return the entity tag of the body, as specified by theETagheader.
setExpires
public void setExpires(ZonedDateTime expires)
Set the duration after which the message is no longer valid, as specified by theExpiresheader.- 从以下版本开始:
- 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 theExpiresheader.- 从以下版本开始:
- 5.2
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.
setHost
public void setHost(@Nullable InetSocketAddress host)
Set the (new) value of theHostheader.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 theHostheader, 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-Matchheader.- 从以下版本开始:
- 4.3
setIfMatch
public void setIfMatch(List<String> ifMatchList)
Set the (new) value of theIf-Matchheader.- 从以下版本开始:
- 4.3
getIfMatch
public List<String> getIfMatch()
Return the value of theIf-Matchheader.- 抛出:
IllegalArgumentException- if parsing fails- 从以下版本开始:
- 4.3
setIfModifiedSince
public void setIfModifiedSince(ZonedDateTime ifModifiedSince)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.- 从以下版本开始:
- 5.1.4
setIfModifiedSince
public void setIfModifiedSince(Instant ifModifiedSince)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.- 从以下版本开始:
- 5.1.4
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.- 抛出:
IllegalArgumentException- if parsing fails
setIfUnmodifiedSince
public void setIfUnmodifiedSince(ZonedDateTime ifUnmodifiedSince)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.- 从以下版本开始:
- 5.1.4
setIfUnmodifiedSince
public void setIfUnmodifiedSince(Instant ifUnmodifiedSince)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.- 从以下版本开始:
- 5.1.4
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.
- 从以下版本开始:
- 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.
- 从以下版本开始:
- 4.3
- 另请参阅:
getFirstZonedDateTime(String)
setLastModified
public void setLastModified(ZonedDateTime lastModified)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.- 从以下版本开始:
- 5.1.4
setLastModified
public void setLastModified(Instant lastModified)
Set the time the resource was last changed, as specified by theLast-Modifiedheader.- 从以下版本开始:
- 5.1.4
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(@Nullable URI location)
Set the (new) location of a resource, as specified by theLocationheader.
getLocation
@Nullable 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(@Nullable String upgrade)
Set the (new) value of theUpgradeheader.
getUpgrade
@Nullable 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.- 参数:
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 raiseIllegalArgumentExceptionif 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, returnnullif there is no value, or raiseIllegalArgumentExceptionif the value cannot be parsed as a date.- 参数:
headerName- the header name- 返回:
- the parsed date header, or
nullif 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
nullif 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)
从接口复制的说明:MultiValueMapAdd 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)
从接口复制的说明:MultiValueMapAdd all the values of the givenMultiValueMapto 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)
从接口复制的说明:MultiValueMapSet the given values under.- 指定者:
setAll在接口中MultiValueMap<String,String>- 参数:
values- the values.
toSingleValueMap
public Map<String,String> toSingleValueMap()
从接口复制的说明:MultiValueMapReturn aMapwith 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-onlyHttpHeaderswrapper 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 regularMapformatting 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- ifusernameorpasswordcontains characters that cannot be encoded to the given charset- 从以下版本开始:
- 5.2
- 另请参阅:
setBasicAuth(String),setBasicAuth(String, String),setBasicAuth(String, String, Charset), RFC 7617