1919import java .util .ArrayList ;
2020import java .util .Collections ;
2121import java .util .List ;
22- import java .util .Map ;
23- import java .util .Set ;
2422
2523import org .jspecify .annotations .Nullable ;
2624
2725import org .springframework .http .HttpHeaders ;
2826import org .springframework .util .CollectionUtils ;
29- import org .springframework .util .MultiValueMap ;
3027
3128/**
32- * An {@link org.springframework.http. HttpHeaders} variant that adds support for
33- * the HTTP headers defined by the WebSocket specification RFC 6455.
29+ * An {@link HttpHeaders} variant that adds support for the HTTP headers defined
30+ * by the WebSocket specification RFC 6455.
3431 *
3532 * @author Rossen Stoyanchev
3633 * @author Sam Brannen
@@ -51,23 +48,32 @@ public class WebSocketHttpHeaders extends HttpHeaders {
5148 private static final long serialVersionUID = -6644521016187828916L ;
5249
5350
54- private final HttpHeaders headers ;
55-
56-
5751 /**
58- * Create a new instance.
52+ * Construct a new, empty {@code WebSocketHttpHeaders} instance.
5953 */
6054 public WebSocketHttpHeaders () {
61- this ( new HttpHeaders () );
55+ super ( );
6256 }
6357
6458 /**
65- * Create an instance that wraps the given pre-existing HttpHeaders and also
66- * propagate all changes to it.
67- * @param headers the HTTP headers to wrap
59+ * Construct a new {@code WebSocketHttpHeaders} instance backed by the supplied
60+ * {@code HttpHeaders}.
61+ * <p>Changes to the {@code WebSocketHttpHeaders} created by this constructor
62+ * will write through to the supplied {@code HttpHeaders}. If you wish to copy
63+ * an existing {@code HttpHeaders} or {@code WebSocketHttpHeaders} instance,
64+ * use {@link #copyOf(HttpHeaders)} instead. Note, however, that {@code copyOf()}
65+ * does not create an instance of {@code WebSocketHttpHeaders}.
66+ * <p>If the supplied {@code HttpHeaders} instance is a
67+ * {@linkplain #readOnlyHttpHeaders(HttpHeaders) read-only}
68+ * {@code HttpHeaders} wrapper, it will be unwrapped to ensure that the
69+ * {@code WebSocketHttpHeaders} instance created by this constructor is mutable.
70+ * Once the writable instance is mutated, the read-only instance is likely to
71+ * be out of sync and should be discarded.
72+ * @param httpHeaders the headers to expose
73+ * @see #copyOf(HttpHeaders)
6874 */
69- public WebSocketHttpHeaders (HttpHeaders headers ) {
70- this . headers = headers ;
75+ public WebSocketHttpHeaders (HttpHeaders httpHeaders ) {
76+ super ( httpHeaders ) ;
7177 }
7278
7379
@@ -182,132 +188,4 @@ public void setSecWebSocketVersion(@Nullable String secWebSocketVersion) {
182188 return getFirst (SEC_WEBSOCKET_VERSION );
183189 }
184190
185- @ Override
186- public @ Nullable List <String > get (String headerName ) {
187- return this .headers .get (headerName );
188- }
189-
190- @ Override
191- public @ Nullable String getFirst (String headerName ) {
192- return this .headers .getFirst (headerName );
193- }
194-
195- @ Override
196- public @ Nullable List <String > put (String key , List <String > value ) {
197- return this .headers .put (key , value );
198- }
199-
200- @ Override
201- public @ Nullable List <String > putIfAbsent (String headerName , List <String > headerValues ) {
202- return this .headers .putIfAbsent (headerName , headerValues );
203- }
204-
205- @ Override
206- public void add (String headerName , @ Nullable String headerValue ) {
207- this .headers .add (headerName , headerValue );
208- }
209-
210- /**
211- * {@inheritDoc}
212- * @since 7.0
213- */
214- @ Override
215- public void addAll (String headerName , List <? extends String > headerValues ) {
216- this .headers .addAll (headerName , headerValues );
217- }
218-
219- @ Override
220- public void set (String headerName , @ Nullable String headerValue ) {
221- this .headers .set (headerName , headerValue );
222- }
223-
224- @ Override
225- public void setAll (Map <String , String > values ) {
226- this .headers .setAll (values );
227- }
228-
229- @ Override
230- public Map <String , String > toSingleValueMap () {
231- return this .headers .toSingleValueMap ();
232- }
233-
234- /**
235- * {@inheritDoc}
236- * @since 7.0
237- * @deprecated in favor of {@link #toSingleValueMap()} which performs a copy but
238- * ensures that collection-iterating methods like {@code entrySet()} are
239- * case-insensitive
240- */
241- @ Override
242- @ Deprecated (since = "7.0" , forRemoval = true )
243- @ SuppressWarnings ("removal" )
244- public Map <String , String > asSingleValueMap () {
245- return this .headers .asSingleValueMap ();
246- }
247-
248- /**
249- * {@inheritDoc}
250- * @since 7.0
251- * @deprecated This method is provided for backward compatibility with APIs
252- * that would only accept maps. Generally avoid using HttpHeaders as a Map
253- * or MultiValueMap.
254- */
255- @ Override
256- @ Deprecated (since = "7.0" , forRemoval = true )
257- @ SuppressWarnings ("removal" )
258- public MultiValueMap <String , String > asMultiValueMap () {
259- return this .headers .asMultiValueMap ();
260- }
261-
262- @ Override
263- public boolean containsHeader (String key ) {
264- return this .headers .containsHeader (key );
265- }
266-
267- @ Override
268- public boolean isEmpty () {
269- return this .headers .isEmpty ();
270- }
271-
272- @ Override
273- public int size () {
274- return this .headers .size ();
275- }
276-
277- @ Override
278- public @ Nullable List <String > remove (String key ) {
279- return this .headers .remove (key );
280- }
281-
282- @ Override
283- public void clear () {
284- this .headers .clear ();
285- }
286-
287- @ Override
288- public Set <String > headerNames () {
289- return this .headers .headerNames ();
290- }
291-
292- @ Override
293- public Set <Map .Entry <String , List <String >>> headerSet () {
294- return this .headers .headerSet ();
295- }
296-
297- @ Override
298- public boolean equals (@ Nullable Object other ) {
299- return (this == other || (other instanceof WebSocketHttpHeaders that &&
300- this .headers .equals (that .headers )));
301- }
302-
303- @ Override
304- public int hashCode () {
305- return this .headers .hashCode ();
306- }
307-
308- @ Override
309- public String toString () {
310- return this .headers .toString ();
311- }
312-
313191}
0 commit comments