public class HttpHeaders extends java.lang.Object implements MultiValueMap<java.lang.String,java.lang.String>, java.io.Serializable
In addition to the normal methods defined by Map, this class offers the following convenience methods:
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 valueInspired by Headers.
| Constructor and Description |
|---|
HttpHeaders()
Constructs a new, empty instance of the
HttpHeaders object. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.lang.String headerName,
java.lang.String headerValue)
Add the given, single header value under the given name.
|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> |
entrySet() |
boolean |
equals(java.lang.Object other) |
java.util.List<java.lang.String> |
get(java.lang.Object key) |
java.util.List<MediaType> |
getAccept()
Return the list of acceptable media types, as specified by the
Accept header. |
java.util.List<java.nio.charset.Charset> |
getAcceptCharset()
Return the list of acceptable charsets, as specified by the
Accept-Charset
header. |
java.util.Set<HttpMethod> |
getAllow()
Return the set of allowed
HTTP methods, as specified by the Allow header. |
java.lang.String |
getCacheControl()
Returns the value of the
Cache-Control header. |
java.util.List<java.lang.String> |
getConnection()
Returns the value of the
Connection header. |
long |
getContentLength()
Return the length of the body in bytes, as specified by the
Content-Length header. |
MediaType |
getContentType()
Return the media type of the body, as specified by the
Content-Type header. |
long |
getDate()
Returns the date and time at which the message was created, as specified by the
Date header. |
java.lang.String |
getETag()
Returns the entity tag of the body, as specified by the
ETag header. |
long |
getExpires()
Returns the date and time at which the message is no longer valid, as specified by the
Expires header. |
java.lang.String |
getFirst(java.lang.String headerName)
Return the first header value for the given header name, if any.
|
java.util.List<java.lang.String> |
getIfNoneMatch()
Returns the value of the
If-None-Match header. |
long |
getIfNotModifiedSince()
Returns the value of the
IfModifiedSince header. |
long |
getLastModified()
Returns the time the resource was last changed, as specified by the
Last-Modified header. |
java.net.URI |
getLocation()
Return the (new) location of a resource, as specified by the
Location header. |
java.lang.String |
getOrigin()
Returns the value of the
Origin header. |
java.lang.String |
getPragma()
Returns the value of the
Pragma header. |
java.lang.String |
getSecWebSocketAccept()
Returns the value of the
Sec-WebSocket-Accept header. |
java.util.List<java.lang.String> |
getSecWebSocketExtensions()
Returns the value of the
Sec-WebSocket-Extensions header. |
java.lang.String |
getSecWebSocketKey()
Returns the value of the
Sec-WebSocket-Key header. |
java.util.List<java.lang.String> |
getSecWebSocketProtocol()
Returns the value of the
Sec-WebSocket-Key header. |
java.lang.String |
getSecWebSocketVersion()
Returns the value of the
Sec-WebSocket-Version header. |
java.lang.String |
getUpgrade()
Returns the value of the
Upgrade header. |
int |
hashCode() |
boolean |
isEmpty() |
java.util.Set<java.lang.String> |
keySet() |
java.util.List<java.lang.String> |
put(java.lang.String key,
java.util.List<java.lang.String> value) |
void |
putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> m) |
static HttpHeaders |
readOnlyHttpHeaders(HttpHeaders headers)
Returns
HttpHeaders object that can only be read, not written to. |
java.util.List<java.lang.String> |
remove(java.lang.Object key) |
void |
set(java.lang.String headerName,
java.lang.String headerValue)
Set the given, single header value under the given name.
|
void |
setAccept(java.util.List<MediaType> acceptableMediaTypes)
Set the list of acceptable media types, as specified by the
Accept header. |
void |
setAcceptCharset(java.util.List<java.nio.charset.Charset> acceptableCharsets)
Set the list of acceptable charsets, as specified by the
Accept-Charset header. |
void |
setAll(java.util.Map<java.lang.String,java.lang.String> values)
Set the given values under.
|
void |
setAllow(java.util.Set<HttpMethod> allowedMethods)
Set the set of allowed
HTTP methods, as specified by the Allow header. |
void |
setCacheControl(java.lang.String cacheControl)
Sets the (new) value of the
Cache-Control header. |
void |
setConnection(java.util.List<java.lang.String> connection)
Sets the (new) value of the
Connection header. |
void |
setConnection(java.lang.String connection)
Sets the (new) value of the
Connection header. |
void |
setContentDispositionFormData(java.lang.String name,
java.lang.String filename)
Sets the (new) value of the
Content-Disposition header for form-data. |
void |
setContentLength(long contentLength)
Set the length of the body in bytes, as specified by the
Content-Length header. |
void |
setContentType(MediaType mediaType)
Set the media type of the body, as specified by the
Content-Type header. |
void |
setDate(long date)
Sets the date and time at which the message was created, as specified by the
Date header. |
void |
setETag(java.lang.String eTag)
Sets the (new) entity tag of the body, as specified by the
ETag header. |
void |
setExpires(long expires)
Sets the date and time at which the message is no longer valid, as specified by the
Expires header. |
void |
setIfModifiedSince(long ifModifiedSince)
Sets the (new) value of the
If-Modified-Since header. |
void |
setIfNoneMatch(java.util.List<java.lang.String> ifNoneMatchList)
Sets the (new) values of the
If-None-Match header. |
void |
setIfNoneMatch(java.lang.String ifNoneMatch)
Sets the (new) value of the
If-None-Match header. |
void |
setLastModified(long lastModified)
Sets the time the resource was last changed, as specified by the
Last-Modified header. |
void |
setLocation(java.net.URI location)
Set the (new) location of a resource, as specified by the
Location header. |
void |
setOrigin(java.lang.String origin)
Sets the (new) value of the
Origin header. |
void |
setPragma(java.lang.String pragma)
Sets the (new) value of the
Pragma header. |
void |
setSecWebSocketAccept(java.lang.String secWebSocketAccept)
Sets the (new) value of the
Sec-WebSocket-Accept header. |
void |
setSecWebSocketExtensions(java.util.List<java.lang.String> secWebSocketExtensions)
Sets the (new) value of the
Sec-WebSocket-Extensions header. |
void |
setSecWebSocketKey(java.lang.String secWebSocketKey)
Sets the (new) value of the
Sec-WebSocket-Key header. |
void |
setSecWebSocketProtocol(java.util.List<java.lang.String> secWebSocketProtocols)
Sets the (new) value of the
Sec-WebSocket-Protocol header. |
void |
setSecWebSocketProtocol(java.lang.String secWebSocketProtocol)
Sets the (new) value of the
Sec-WebSocket-Protocol header. |
void |
setSecWebSocketVersion(java.lang.String secWebSocketVersion)
Sets the (new) value of the
Sec-WebSocket-Version header. |
void |
setUpgrade(java.lang.String upgrade)
Sets the (new) value of the
Upgrade header. |
int |
size() |
java.util.Map<java.lang.String,java.lang.String> |
toSingleValueMap()
Returns the first values contained in this
MultiValueMap. |
java.lang.String |
toString() |
java.util.Collection<java.util.List<java.lang.String>> |
values() |
public HttpHeaders()
HttpHeaders object.public static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
HttpHeaders object that can only be read, not written to.public void setAccept(java.util.List<MediaType> acceptableMediaTypes)
Accept header.acceptableMediaTypes - the acceptable media typespublic java.util.List<MediaType> getAccept()
Accept header.
Returns an empty list when the acceptable media types are unspecified.
public void setAcceptCharset(java.util.List<java.nio.charset.Charset> acceptableCharsets)
Accept-Charset header.acceptableCharsets - the acceptable charsetspublic java.util.List<java.nio.charset.Charset> getAcceptCharset()
Accept-Charset
header.public void setAllow(java.util.Set<HttpMethod> allowedMethods)
HTTP methods, as specified by the Allow header.allowedMethods - the allowed methodspublic java.util.Set<HttpMethod> getAllow()
HTTP methods, as specified by the Allow header.
Returns an empty set when the allowed methods are unspecified.
public void setCacheControl(java.lang.String cacheControl)
Cache-Control header.cacheControl - the value of the headerpublic java.lang.String getCacheControl()
Cache-Control header.public void setConnection(java.lang.String connection)
Connection header.connection - the value of the headerpublic void setConnection(java.util.List<java.lang.String> connection)
Connection header.connection - the value of the headerpublic java.util.List<java.lang.String> getConnection()
Connection header.public void setContentDispositionFormData(java.lang.String name,
java.lang.String filename)
Content-Disposition header for form-data.name - the control namefilename - the filename, may be nullpublic void setContentLength(long contentLength)
Content-Length header.contentLength - the content lengthpublic long getContentLength()
Content-Length header.
Returns -1 when the content-length is unknown.
public void setContentType(MediaType mediaType)
Content-Type header.mediaType - the media typepublic MediaType getContentType()
Content-Type header.
Returns null when the content-type is unknown.
public void setDate(long date)
Date header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
date - the datepublic long getDate()
Date header.
The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
java.lang.IllegalArgumentException - if the value can't be converted to a datepublic void setETag(java.lang.String eTag)
ETag header.eTag - the new entity tagpublic java.lang.String getETag()
ETag header.public void setExpires(long expires)
Expires header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
expires - the new expires header valuepublic long getExpires()
Expires header.
The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
public void setIfModifiedSince(long ifModifiedSince)
If-Modified-Since header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
ifModifiedSince - the new value of the headerpublic long getIfNotModifiedSince()
IfModifiedSince header.
The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
public void setIfNoneMatch(java.lang.String ifNoneMatch)
If-None-Match header.ifNoneMatch - the new value of the headerpublic void setIfNoneMatch(java.util.List<java.lang.String> ifNoneMatchList)
If-None-Match header.ifNoneMatchList - the new value of the headerpublic java.util.List<java.lang.String> getIfNoneMatch()
If-None-Match header.public void setLastModified(long lastModified)
Last-Modified header.
The date should be specified as the number of milliseconds since January 1, 1970 GMT.
lastModified - the last modified datepublic long getLastModified()
Last-Modified header.
The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
public void setLocation(java.net.URI location)
Location header.location - the locationpublic java.net.URI getLocation()
Location header.
Returns null when the location is unknown.
public void setOrigin(java.lang.String origin)
Origin header.origin - the value of the headerpublic java.lang.String getOrigin()
Origin header.public void setSecWebSocketAccept(java.lang.String secWebSocketAccept)
Sec-WebSocket-Accept header.secWebSocketAccept - the value of the headerpublic java.lang.String getSecWebSocketAccept()
Sec-WebSocket-Accept header.public java.util.List<java.lang.String> getSecWebSocketExtensions()
Sec-WebSocket-Extensions header.public void setSecWebSocketExtensions(java.util.List<java.lang.String> secWebSocketExtensions)
Sec-WebSocket-Extensions header.secWebSocketExtensions - the value of the headerpublic void setSecWebSocketKey(java.lang.String secWebSocketKey)
Sec-WebSocket-Key header.secWebSocketKey - the value of the headerpublic java.lang.String getSecWebSocketKey()
Sec-WebSocket-Key header.public void setSecWebSocketProtocol(java.lang.String secWebSocketProtocol)
Sec-WebSocket-Protocol header.secWebSocketProtocol - the value of the headerpublic void setSecWebSocketProtocol(java.util.List<java.lang.String> secWebSocketProtocols)
Sec-WebSocket-Protocol header.secWebSocketProtocols - the value of the headerpublic java.util.List<java.lang.String> getSecWebSocketProtocol()
Sec-WebSocket-Key header.public void setSecWebSocketVersion(java.lang.String secWebSocketVersion)
Sec-WebSocket-Version header.secWebSocketKey - the value of the headerpublic java.lang.String getSecWebSocketVersion()
Sec-WebSocket-Version header.public void setPragma(java.lang.String pragma)
Pragma header.pragma - the value of the headerpublic java.lang.String getPragma()
Pragma header.public void setUpgrade(java.lang.String upgrade)
Upgrade header.upgrade - the value of the headerpublic java.lang.String getUpgrade()
Upgrade header.public java.lang.String getFirst(java.lang.String headerName)
getFirst in interface MultiValueMap<java.lang.String,java.lang.String>headerName - the header namenullpublic void add(java.lang.String headerName,
java.lang.String headerValue)
add in interface MultiValueMap<java.lang.String,java.lang.String>headerName - the header nameheaderValue - the header valuejava.lang.UnsupportedOperationException - if adding headers is not supportedput(String, List),
set(String, String)public void set(java.lang.String headerName,
java.lang.String headerValue)
set in interface MultiValueMap<java.lang.String,java.lang.String>headerName - the header nameheaderValue - the header valuejava.lang.UnsupportedOperationException - if adding headers is not supportedput(String, List),
add(String, String)public void setAll(java.util.Map<java.lang.String,java.lang.String> values)
MultiValueMapsetAll in interface MultiValueMap<java.lang.String,java.lang.String>values - the values.public java.util.Map<java.lang.String,java.lang.String> toSingleValueMap()
MultiValueMapMultiValueMap.toSingleValueMap in interface MultiValueMap<java.lang.String,java.lang.String>public int size()
size in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public boolean isEmpty()
isEmpty in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public boolean containsKey(java.lang.Object key)
containsKey in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public boolean containsValue(java.lang.Object value)
containsValue in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public java.util.List<java.lang.String> get(java.lang.Object key)
get in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public java.util.List<java.lang.String> put(java.lang.String key,
java.util.List<java.lang.String> value)
put in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public java.util.List<java.lang.String> remove(java.lang.Object key)
remove in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public void putAll(java.util.Map<? extends java.lang.String,? extends java.util.List<java.lang.String>> m)
putAll in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public void clear()
clear in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public java.util.Set<java.lang.String> keySet()
keySet in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public java.util.Collection<java.util.List<java.lang.String>> values()
values in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public java.util.Set<java.util.Map.Entry<java.lang.String,java.util.List<java.lang.String>>> entrySet()
entrySet in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>public boolean equals(java.lang.Object other)
equals in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>equals in class java.lang.Objectpublic int hashCode()
hashCode in interface java.util.Map<java.lang.String,java.util.List<java.lang.String>>hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object