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
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class 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
ConstructorsConstructorDescriptionCreate 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 TypeMethodDescriptionvoidAdd the given, single header value under the given name.voidclear()Remove all headers from this HttpHeaders instance.booleancontainsHeader(String key) Returnstrueif this HttpHeaders contains an entry for the given header name.booleanvoidforEach(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-Acceptheader.Returns the value of theSec-WebSocket-Extensionsheader.Returns the value of theSec-WebSocket-Keyheader.Returns the value of theSec-WebSocket-Protocolheader.Returns the value of theSec-WebSocket-Versionheader.inthashCode()Return the set of header names.Return a view of the headers as an entrySetof key-list pairs.booleanisEmpty()Returnstrueif this HttpHeaders contains no header entry.Set the list of values associated with the given header name.voidPut all the entries from the givenMultiValueMapinto this HttpHeaders.voidputAll(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 ornullif that header wasn't present.voidSet the given, single header value under the given name.voidSet all single header value from the given Map under each of their corresponding name.voidsetSecWebSocketAccept(@Nullable String secWebSocketAccept) Sets the (new) value of theSec-WebSocket-Acceptheader.voidsetSecWebSocketExtensions(List<WebSocketExtension> extensions) Sets the (new) value(s) of theSec-WebSocket-Extensionsheader.voidsetSecWebSocketKey(@Nullable String secWebSocketKey) Sets the (new) value of theSec-WebSocket-Keyheader.voidsetSecWebSocketProtocol(String secWebSocketProtocol) Sets the (new) value of theSec-WebSocket-Protocolheader.voidsetSecWebSocketProtocol(List<String> secWebSocketProtocols) Sets the (new) value of theSec-WebSocket-Protocolheader.voidsetSecWebSocketVersion(@Nullable String secWebSocketVersion) Sets the (new) value of theSec-WebSocket-Versionheader.intsize()Return the number of headers in the collection.Return this HttpHeaders as aMapwith the first values for each header name.toString()Methods inherited from class HttpHeaders
addAll, addAll, asMultiValueMap, asSingleValueMap, clearContentHeaders, containsHeaderValue, copyOf, copyOf, 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
-
getSecWebSocketAccept
-
getSecWebSocketExtensions
Returns the value of theSec-WebSocket-Extensionsheader.- Returns:
- the value of the header
-
setSecWebSocketExtensions
Sets the (new) value(s) of theSec-WebSocket-Extensionsheader.- Parameters:
extensions- the values for the header
-
setSecWebSocketKey
-
getSecWebSocketKey
-
setSecWebSocketProtocol
Sets the (new) value of theSec-WebSocket-Protocolheader.- Parameters:
secWebSocketProtocol- the value of the header
-
setSecWebSocketProtocol
-
getSecWebSocketProtocol
-
setSecWebSocketVersion
-
getSecWebSocketVersion
-
getFirst
Return the first header value for the given header name, if any.- Overrides:
getFirstin 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:
addin 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:
setin classHttpHeaders- Parameters:
headerName- the header nameheaderValue- the header value- Throws:
UnsupportedOperationException- if adding headers is not supported- See Also:
-
setAll
Description copied from class:HttpHeadersSet all single header value from the given Map under each of their corresponding name.- Overrides:
setAllin classHttpHeaders- Parameters:
values- the name-single-value pairs- See Also:
-
toSingleValueMap
Description copied from class:HttpHeadersReturn this HttpHeaders as aMapwith 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:
toSingleValueMapin classHttpHeaders- Returns:
- a single value representation of these headers
-
size
public int size()Description copied from class:HttpHeadersReturn the number of headers in the collection. This can be inflated, seeclass level javadoc.- Overrides:
sizein classHttpHeaders
-
isEmpty
public boolean isEmpty()Description copied from class:HttpHeadersReturnstrueif this HttpHeaders contains no header entry.- Overrides:
isEmptyin classHttpHeaders
-
containsHeader
Description copied from class:HttpHeadersReturnstrueif this HttpHeaders contains an entry for the given header name.- Overrides:
containsHeaderin classHttpHeaders- Parameters:
key- the header name
-
get
Description copied from class:HttpHeadersGet 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:
getin classHttpHeaders- Parameters:
headerName- the header name- See Also:
-
put
Description copied from class:HttpHeadersSet the list of values associated with the given header name. Returns the previous list of values, ornullif the header was not present.- Overrides:
putin classHttpHeaders- Parameters:
key- the header namevalue- the new values- Returns:
- the old values for the given header name
-
remove
Description copied from class:HttpHeadersRemove a header from this HttpHeaders instance, and return the associated value list ornullif that header wasn't present.- Overrides:
removein 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:HttpHeadersPut all the entries from the given HttpHeaders into this HttpHeaders.- Overrides:
putAllin classHttpHeaders- Parameters:
headers- the given headers- See Also:
-
putAll
Description copied from class:HttpHeadersPut all the entries from the givenMultiValueMapinto this HttpHeaders.- Overrides:
putAllin classHttpHeaders- Parameters:
m- the given headers- See Also:
-
clear
public void clear()Description copied from class:HttpHeadersRemove all headers from this HttpHeaders instance.- Overrides:
clearin classHttpHeaders
-
headerNames
Description copied from class:HttpHeadersReturn 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:
headerNamesin classHttpHeaders- Returns:
- a
Setof all the headers names
-
headerSet
Description copied from class:HttpHeadersReturn a view of the headers as an entrySetof 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:
headerSetin classHttpHeaders- Returns:
- a
Setview that iterates over all headers in a case-insensitive manner
-
forEach
Description copied from class:HttpHeadersPerform an action over each header, as when iterated viaHttpHeaders.headerSet().- Overrides:
forEachin classHttpHeaders- Parameters:
action- the action to be performed for each entry
-
putIfAbsent
Description copied from class:HttpHeadersSet 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:
putIfAbsentin classHttpHeaders- Parameters:
headerName- the header nameheaderValues- the header values to set if header is not present- Returns:
- the previous value or
null
-
equals
- Overrides:
equalsin classHttpHeaders
-
hashCode
public int hashCode()- Overrides:
hashCodein classHttpHeaders
-
toString
- Overrides:
toStringin classHttpHeaders
-