Class WebSocketHttpHeaders

java.lang.Object
org.springframework.http.HttpHeaders
org.springframework.web.socket.WebSocketHttpHeaders
All Implemented Interfaces:
Serializable

public class WebSocketHttpHeaders extends HttpHeaders
An 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 Details

  • Constructor Details

    • WebSocketHttpHeaders

      public WebSocketHttpHeaders()
      Create a new instance.
    • WebSocketHttpHeaders

      public WebSocketHttpHeaders(HttpHeaders headers)
      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

      public void setSecWebSocketAccept(@Nullable String secWebSocketAccept)
      Sets the (new) value of the Sec-WebSocket-Accept header.
      Parameters:
      secWebSocketAccept - the value of the header
    • getSecWebSocketAccept

      public @Nullable String getSecWebSocketAccept()
      Returns the value of the Sec-WebSocket-Accept header.
      Returns:
      the value of the header
    • getSecWebSocketExtensions

      public List<WebSocketExtension> getSecWebSocketExtensions()
      Returns the value of the Sec-WebSocket-Extensions header.
      Returns:
      the value of the header
    • setSecWebSocketExtensions

      public void setSecWebSocketExtensions(List<WebSocketExtension> extensions)
      Sets the (new) value(s) of the Sec-WebSocket-Extensions header.
      Parameters:
      extensions - the values for the header
    • setSecWebSocketKey

      public void setSecWebSocketKey(@Nullable String secWebSocketKey)
      Sets the (new) value of the Sec-WebSocket-Key header.
      Parameters:
      secWebSocketKey - the value of the header
    • getSecWebSocketKey

      public @Nullable String getSecWebSocketKey()
      Returns the value of the Sec-WebSocket-Key header.
      Returns:
      the value of the header
    • setSecWebSocketProtocol

      public void setSecWebSocketProtocol(String secWebSocketProtocol)
      Sets the (new) value of the Sec-WebSocket-Protocol header.
      Parameters:
      secWebSocketProtocol - the value of the header
    • setSecWebSocketProtocol

      public void setSecWebSocketProtocol(List<String> secWebSocketProtocols)
      Sets the (new) value of the Sec-WebSocket-Protocol header.
      Parameters:
      secWebSocketProtocols - the value of the header
    • getSecWebSocketProtocol

      public List<String> getSecWebSocketProtocol()
      Returns the value of the Sec-WebSocket-Key header.
      Returns:
      the value of the header
    • setSecWebSocketVersion

      public void setSecWebSocketVersion(@Nullable String secWebSocketVersion)
      Sets the (new) value of the Sec-WebSocket-Version header.
      Parameters:
      secWebSocketVersion - the value of the header
    • getSecWebSocketVersion

      public @Nullable String getSecWebSocketVersion()
      Returns the value of the Sec-WebSocket-Version header.
      Returns:
      the value of the header
    • getFirst

      public @Nullable String getFirst(String headerName)
      Return the first header value for the given header name, if any.
      Overrides:
      getFirst in class HttpHeaders
      Parameters:
      headerName - the header name
      Returns:
      the first header value; or null
    • add

      public void add(String headerName, @Nullable String headerValue)
      Add the given, single header value under the given name.
      Overrides:
      add in class HttpHeaders
      Parameters:
      headerName - the header name
      headerValue - the header value
      Throws:
      UnsupportedOperationException - if adding headers is not supported
      See Also:
    • set

      public void set(String headerName, @Nullable String headerValue)
      Set the given, single header value under the given name.
      Overrides:
      set in class HttpHeaders
      Parameters:
      headerName - the header name
      headerValue - the header value
      Throws:
      UnsupportedOperationException - if adding headers is not supported
      See Also:
    • setAll

      public void setAll(Map<String,String> values)
      Description copied from class: HttpHeaders
      Set all single header value from the given Map under each of their corresponding name.
      Overrides:
      setAll in class HttpHeaders
      Parameters:
      values - the name-single-value pairs
      See Also:
    • toSingleValueMap

      public Map<String,String> toSingleValueMap()
      Description copied from class: HttpHeaders
      Return this HttpHeaders as a Map 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 like entrySet() are case-insensitive.

      Overrides:
      toSingleValueMap in class HttpHeaders
      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, see class level javadoc.
      Overrides:
      size in class HttpHeaders
    • isEmpty

      public boolean isEmpty()
      Description copied from class: HttpHeaders
      Returns true if this HttpHeaders contains no header entry.
      Overrides:
      isEmpty in class HttpHeaders
    • containsHeader

      public boolean containsHeader(String key)
      Description copied from class: HttpHeaders
      Returns true if this HttpHeaders contains an entry for the given header name.
      Overrides:
      containsHeader in class HttpHeaders
      Parameters:
      key - the header name
    • get

      public @Nullable List<String> get(String headerName)
      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 class HttpHeaders
      Parameters:
      headerName - the header name
      See Also:
    • put

      public @Nullable List<String> put(String key, List<String> value)
      Description copied from class: HttpHeaders
      Set the list of values associated with the given header name. Returns the previous list of values, or null if the header was not present.
      Overrides:
      put in class HttpHeaders
      Parameters:
      key - the header name
      value - the new values
      Returns:
      the old values for the given header name
    • remove

      public @Nullable List<String> remove(String key)
      Description copied from class: HttpHeaders
      Remove a header from this HttpHeaders instance, and return the associated value list or null if that header wasn't present.
      Overrides:
      remove in class HttpHeaders
      Parameters:
      key - the name of the header to remove
      Returns:
      the value list associated with the removed header name
    • putAll

      public void putAll(HttpHeaders headers)
      Description copied from class: HttpHeaders
      Put all the entries from the given HttpHeaders into this HttpHeaders.
      Overrides:
      putAll in class HttpHeaders
      Parameters:
      headers - the given headers
      See Also:
    • putAll

      public void putAll(Map<? extends String,? extends List<String>> m)
      Description copied from class: HttpHeaders
      Put all the entries from the given MultiValueMap into this HttpHeaders.
      Overrides:
      putAll in class HttpHeaders
      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 class HttpHeaders
    • headerNames

      public Set<String> headerNames()
      Description copied from class: HttpHeaders
      Return the set of header names. Both Set.remove(Object) and Set.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 class HttpHeaders
      Returns:
      a Set of all the headers names
    • headerSet

      public Set<Map.Entry<String,List<String>>> headerSet()
      Description copied from class: HttpHeaders
      Return a view of the headers as an entry Set of key-list pairs. Both Iterator.remove() and Map.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 class HttpHeaders
      Returns:
      a Set view that iterates over all headers in a case-insensitive manner
    • forEach

      public void forEach(BiConsumer<? super String,? super List<String>> action)
      Description copied from class: HttpHeaders
      Perform an action over each header, as when iterated via HttpHeaders.headerSet().
      Overrides:
      forEach in class HttpHeaders
      Parameters:
      action - the action to be performed for each entry
    • putIfAbsent

      public @Nullable List<String> putIfAbsent(String headerName, List<String> headerValues)
      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 return null. If the header is already present, returns the associated value list instead.
      Overrides:
      putIfAbsent in class HttpHeaders
      Parameters:
      headerName - the header name
      headerValues - the header values to set if header is not present
      Returns:
      the previous value or null
    • equals

      public boolean equals(@Nullable Object other)
      Overrides:
      equals in class HttpHeaders
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class HttpHeaders
    • toString

      public String toString()
      Overrides:
      toString in class HttpHeaders