Class WebSocketHttpHeaders
- All Implemented Interfaces:
Serializable
HttpHeaders
variant that adds support for
the HTTP headers defined by the WebSocket specification RFC 6455.- Since:
- 4.0
- Author:
- Rossen Stoyanchev
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
Fields inherited from class org.springframework.http.HttpHeaders
ACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, ACCEPT_PATCH, ACCEPT_RANGES, ACCESS_CONTROL_ALLOW_CREDENTIALS, ACCESS_CONTROL_ALLOW_HEADERS, ACCESS_CONTROL_ALLOW_METHODS, ACCESS_CONTROL_ALLOW_ORIGIN, ACCESS_CONTROL_EXPOSE_HEADERS, ACCESS_CONTROL_MAX_AGE, ACCESS_CONTROL_REQUEST_HEADERS, ACCESS_CONTROL_REQUEST_METHOD, AGE, ALLOW, AUTHORIZATION, CACHE_CONTROL, CONNECTION, CONTENT_DISPOSITION, CONTENT_ENCODING, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_RANGE, CONTENT_TYPE, COOKIE, DATE, EMPTY, ETAG, EXPECT, EXPIRES, FROM, HOST, IF_MATCH, IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_RANGE, IF_UNMODIFIED_SINCE, LAST_MODIFIED, LINK, LOCATION, MAX_FORWARDS, ORIGIN, PRAGMA, PROXY_AUTHENTICATE, PROXY_AUTHORIZATION, RANGE, REFERER, RETRY_AFTER, SERVER, SET_COOKIE, SET_COOKIE2, TE, TRAILER, TRANSFER_ENCODING, UPGRADE, USER_AGENT, VARY, VIA, WARNING, WWW_AUTHENTICATE
-
Constructor Summary
ConstructorDescriptionCreate a new instance.WebSocketHttpHeaders
(HttpHeaders headers) Create an instance that wraps the given pre-existing HttpHeaders and also propagate all changes to it. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the given, single header value under the given name.void
clear()
Remove all headers from this HttpHeaders instance.boolean
containsHeader
(String key) Returnstrue
if this HttpHeaders contains an entry for the given header name.boolean
void
forEach
(BiConsumer<? super String, ? super List<String>> action) Perform an action over each header, as when iterated viaHttpHeaders.headerSet()
.Get the list of values associated with the given header name, or null.Return the first header value for the given header name, if any.Returns the value of theSec-WebSocket-Accept
header.Returns the value of theSec-WebSocket-Extensions
header.Returns the value of theSec-WebSocket-Key
header.Returns the value of theSec-WebSocket-Key
header.Returns the value of theSec-WebSocket-Version
header.int
hashCode()
Return the set of header names.Return a view of the headers as an entrySet
of key-list pairs.boolean
isEmpty()
Returnstrue
if this HttpHeaders contains no header entry.Set the list of values associated with the given header name.void
Put all the entries from the givenMultiValueMap
into this HttpHeaders.void
putAll
(HttpHeaders headers) Put all the entries from the given HttpHeaders into this HttpHeaders.putIfAbsent
(String headerName, List<String> headerValues) Set header values for the given header name if that header name isn't already present in this HttpHeaders and returnnull
.Remove a header from this HttpHeaders instance, and return the associated value list ornull
if that header wasn't present.void
Set the given, single header value under the given name.void
Set all single header value from the given Map under each of their corresponding name.void
setSecWebSocketAccept
(@Nullable String secWebSocketAccept) Sets the (new) value of theSec-WebSocket-Accept
header.void
setSecWebSocketExtensions
(List<WebSocketExtension> extensions) Sets the (new) value(s) of theSec-WebSocket-Extensions
header.void
setSecWebSocketKey
(@Nullable String secWebSocketKey) Sets the (new) value of theSec-WebSocket-Key
header.void
setSecWebSocketProtocol
(String secWebSocketProtocol) Sets the (new) value of theSec-WebSocket-Protocol
header.void
setSecWebSocketProtocol
(List<String> secWebSocketProtocols) Sets the (new) value of theSec-WebSocket-Protocol
header.void
setSecWebSocketVersion
(@Nullable String secWebSocketVersion) Sets the (new) value of theSec-WebSocket-Version
header.int
size()
Return the number of headers in the collection.Return this HttpHeaders as aMap
with the first values for each header name.toString()
Methods inherited from class org.springframework.http.HttpHeaders
addAll, addAll, asMultiValueMap, asSingleValueMap, clearContentHeaders, containsHeaderValue, encodeBasicAuth, formatHeaders, getAccept, getAcceptCharset, getAcceptLanguage, getAcceptLanguageAsLocales, getAcceptPatch, getAccessControlAllowCredentials, getAccessControlAllowHeaders, getAccessControlAllowMethods, getAccessControlAllowOrigin, getAccessControlExposeHeaders, getAccessControlMaxAge, getAccessControlRequestHeaders, getAccessControlRequestMethod, getAllow, getCacheControl, getConnection, getContentDisposition, getContentLanguage, getContentLength, getContentType, getDate, getETag, getETagValuesAsList, getExpires, getFieldValues, getFirstDate, getFirstZonedDateTime, getHost, getIfMatch, getIfModifiedSince, getIfNoneMatch, getIfUnmodifiedSince, getLastModified, getLocation, getOrDefault, getOrEmpty, getOrigin, getPragma, getRange, getUpgrade, getValuesAsList, getVary, hasHeaderValues, readOnlyHttpHeaders, readOnlyHttpHeaders, setAccept, setAcceptCharset, setAcceptLanguage, setAcceptLanguageAsLocales, setAcceptPatch, setAccessControlAllowCredentials, setAccessControlAllowHeaders, setAccessControlAllowMethods, setAccessControlAllowOrigin, setAccessControlExposeHeaders, setAccessControlMaxAge, setAccessControlMaxAge, setAccessControlRequestHeaders, setAccessControlRequestMethod, setAllow, setBasicAuth, setBasicAuth, setBasicAuth, setBearerAuth, setCacheControl, setCacheControl, setConnection, setConnection, setContentDisposition, setContentDispositionFormData, setContentLanguage, setContentLength, setContentType, setDate, setDate, setDate, setDate, setETag, setExpires, setExpires, setExpires, setHost, setIfMatch, setIfMatch, setIfModifiedSince, setIfModifiedSince, setIfModifiedSince, setIfNoneMatch, setIfNoneMatch, setIfUnmodifiedSince, setIfUnmodifiedSince, setIfUnmodifiedSince, setInstant, setLastModified, setLastModified, setLastModified, setLocation, setOrigin, setPragma, setRange, setUpgrade, setVary, setZonedDateTime, toCommaDelimitedString
-
Field Details
-
SEC_WEBSOCKET_ACCEPT
- See Also:
-
SEC_WEBSOCKET_EXTENSIONS
- See Also:
-
SEC_WEBSOCKET_KEY
- See Also:
-
SEC_WEBSOCKET_PROTOCOL
- See Also:
-
SEC_WEBSOCKET_VERSION
- See Also:
-
-
Constructor Details
-
WebSocketHttpHeaders
public WebSocketHttpHeaders()Create a new instance. -
WebSocketHttpHeaders
Create an instance that wraps the given pre-existing HttpHeaders and also propagate all changes to it.- Parameters:
headers
- the HTTP headers to wrap
-
-
Method Details
-
setSecWebSocketAccept
Sets the (new) value of theSec-WebSocket-Accept
header.- Parameters:
secWebSocketAccept
- the value of the header
-
getSecWebSocketAccept
Returns the value of theSec-WebSocket-Accept
header.- Returns:
- the value of the header
-
getSecWebSocketExtensions
Returns the value of theSec-WebSocket-Extensions
header.- Returns:
- the value of the header
-
setSecWebSocketExtensions
Sets the (new) value(s) of theSec-WebSocket-Extensions
header.- Parameters:
extensions
- the values for the header
-
setSecWebSocketKey
Sets the (new) value of theSec-WebSocket-Key
header.- Parameters:
secWebSocketKey
- the value of the header
-
getSecWebSocketKey
Returns the value of theSec-WebSocket-Key
header.- Returns:
- the value of the header
-
setSecWebSocketProtocol
Sets the (new) value of theSec-WebSocket-Protocol
header.- Parameters:
secWebSocketProtocol
- the value of the header
-
setSecWebSocketProtocol
Sets the (new) value of theSec-WebSocket-Protocol
header.- Parameters:
secWebSocketProtocols
- the value of the header
-
getSecWebSocketProtocol
Returns the value of theSec-WebSocket-Key
header.- Returns:
- the value of the header
-
setSecWebSocketVersion
Sets the (new) value of theSec-WebSocket-Version
header.- Parameters:
secWebSocketVersion
- the value of the header
-
getSecWebSocketVersion
Returns the value of theSec-WebSocket-Version
header.- Returns:
- the value of the header
-
getFirst
Return the first header value for the given header name, if any.- Overrides:
getFirst
in classHttpHeaders
- Parameters:
headerName
- the header name- Returns:
- the first header value; or
null
-
add
Add the given, single header value under the given name.- Overrides:
add
in classHttpHeaders
- Parameters:
headerName
- the header nameheaderValue
- the header value- Throws:
UnsupportedOperationException
- if adding headers is not supported- See Also:
-
set
Set the given, single header value under the given name.- Overrides:
set
in classHttpHeaders
- Parameters:
headerName
- the header nameheaderValue
- the header value- Throws:
UnsupportedOperationException
- if adding headers is not supported- See Also:
-
setAll
Description copied from class:HttpHeaders
Set all single header value from the given Map under each of their corresponding name.- Overrides:
setAll
in classHttpHeaders
- Parameters:
values
- the name-single-value pairs- See Also:
-
toSingleValueMap
Description copied from class:HttpHeaders
Return this HttpHeaders as aMap
with the first values for each header name.The difference between this method and
HttpHeaders.asSingleValueMap()
is that this method returns a copy of the headers, whereas the latter returns a view. This copy also ensures that collection-iterating methods likeentrySet()
are case-insensitive.- Overrides:
toSingleValueMap
in classHttpHeaders
- Returns:
- a single value representation of these headers
-
size
public int size()Description copied from class:HttpHeaders
Return the number of headers in the collection. This can be inflated, seeclass level javadoc
.- Overrides:
size
in classHttpHeaders
-
isEmpty
public boolean isEmpty()Description copied from class:HttpHeaders
Returnstrue
if this HttpHeaders contains no header entry.- Overrides:
isEmpty
in classHttpHeaders
-
containsHeader
Description copied from class:HttpHeaders
Returnstrue
if this HttpHeaders contains an entry for the given header name.- Overrides:
containsHeader
in classHttpHeaders
- Parameters:
key
- the header name
-
get
Description copied from class:HttpHeaders
Get the list of values associated with the given header name, or null.To ensure support for double-quoted values, see also
HttpHeaders.getValuesAsList(String)
.- Overrides:
get
in classHttpHeaders
- Parameters:
headerName
- the header name- See Also:
-
put
Description copied from class:HttpHeaders
Set the list of values associated with the given header name. Returns the previous list of values, ornull
if the header was not present.- Overrides:
put
in classHttpHeaders
- Parameters:
key
- the header namevalue
- the new values- Returns:
- the old values for the given header name
-
remove
Description copied from class:HttpHeaders
Remove a header from this HttpHeaders instance, and return the associated value list ornull
if that header wasn't present.- Overrides:
remove
in classHttpHeaders
- Parameters:
key
- the name of the header to remove- Returns:
- the value list associated with the removed header name
-
putAll
Description copied from class:HttpHeaders
Put all the entries from the given HttpHeaders into this HttpHeaders.- Overrides:
putAll
in classHttpHeaders
- Parameters:
headers
- the given headers- See Also:
-
putAll
Description copied from class:HttpHeaders
Put all the entries from the givenMultiValueMap
into this HttpHeaders.- Overrides:
putAll
in classHttpHeaders
- Parameters:
m
- the given headers- See Also:
-
clear
public void clear()Description copied from class:HttpHeaders
Remove all headers from this HttpHeaders instance.- Overrides:
clear
in classHttpHeaders
-
headerNames
Description copied from class:HttpHeaders
Return the set of header names. BothSet.remove(Object)
andSet.clear()
operations are supported and mutate the headers.This collection is guaranteed to contain only one casing variant of each header name even if the backing structure stores multiple casing variants of names. The first encountered variant is the one that is retained.
- Overrides:
headerNames
in classHttpHeaders
- Returns:
- a
Set
of all the headers names
-
headerSet
Description copied from class:HttpHeaders
Return a view of the headers as an entrySet
of key-list pairs. BothIterator.remove()
andMap.Entry.setValue(V)
are supported and mutate the headers.This collection is guaranteed to contain one entry per header name even if the backing structure stores multiple casing variants of names, at the cost of first copying the names into a case-insensitive set for filtering the iteration.
- Overrides:
headerSet
in classHttpHeaders
- Returns:
- a
Set
view that iterates over all headers in a case-insensitive manner
-
forEach
Description copied from class:HttpHeaders
Perform an action over each header, as when iterated viaHttpHeaders.headerSet()
.- Overrides:
forEach
in classHttpHeaders
- Parameters:
action
- the action to be performed for each entry
-
putIfAbsent
Description copied from class:HttpHeaders
Set header values for the given header name if that header name isn't already present in this HttpHeaders and returnnull
. If the header is already present, returns the associated value list instead.- Overrides:
putIfAbsent
in classHttpHeaders
- Parameters:
headerName
- the header nameheaderValues
- the header values to set if header is not present- Returns:
- the previous value or
null
-
equals
- Overrides:
equals
in classHttpHeaders
-
hashCode
public int hashCode()- Overrides:
hashCode
in classHttpHeaders
-
toString
- Overrides:
toString
in classHttpHeaders
-