@ -21,18 +21,19 @@ import java.util.Collections;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.Set ;
import java.util.Set ;
import java.util.function.BiConsumer ;
import org.jspecify.annotations.Nullable ;
import org.jspecify.annotations.Nullable ;
import org.springframework.http.HttpHeaders ;
import org.springframework.http.HttpHeaders ;
import org.springframework.util.CollectionUtils ;
import org.springframework.util.CollectionUtils ;
import org.springframework.util.MultiValueMap ;
/ * *
/ * *
* An { @link org . springframework . http . HttpHeaders } variant that adds support for
* An { @link org . springframework . http . HttpHeaders } variant that adds support for
* the HTTP headers defined by the WebSocket specification RFC 6455 .
* the HTTP headers defined by the WebSocket specification RFC 6455 .
*
*
* @author Rossen Stoyanchev
* @author Rossen Stoyanchev
* @author Sam Brannen
* @since 4 . 0
* @since 4 . 0
* /
* /
public class WebSocketHttpHeaders extends HttpHeaders {
public class WebSocketHttpHeaders extends HttpHeaders {
@ -181,40 +182,40 @@ public class WebSocketHttpHeaders extends HttpHeaders {
return getFirst ( SEC_WEBSOCKET_VERSION ) ;
return getFirst ( SEC_WEBSOCKET_VERSION ) ;
}
}
@Override
public @Nullable List < String > get ( String headerName ) {
return this . headers . get ( headerName ) ;
}
// Single string methods
/ * *
* Return the first header value for the given header name , if any .
* @param headerName the header name
* @return the first header value ; or { @code null }
* /
@Override
@Override
public @Nullable String getFirst ( String headerName ) {
public @Nullable String getFirst ( String headerName ) {
return this . headers . getFirst ( headerName ) ;
return this . headers . getFirst ( headerName ) ;
}
}
/ * *
@Override
* Add the given , single header value under the given name .
public @Nullable List < String > put ( String key , List < String > value ) {
* @param headerName the header name
return this . headers . put ( key , value ) ;
* @param headerValue the header value
}
* @throws UnsupportedOperationException if adding headers is not supported
* @see # put ( String , List )
@Override
* @see # set ( String , String )
public @Nullable List < String > putIfAbsent ( String headerName , List < String > headerValues ) {
* /
return this . headers . putIfAbsent ( headerName , headerValues ) ;
}
@Override
@Override
public void add ( String headerName , @Nullable String headerValue ) {
public void add ( String headerName , @Nullable String headerValue ) {
this . headers . add ( headerName , headerValue ) ;
this . headers . add ( headerName , headerValue ) ;
}
}
/ * *
/ * *
* Set the given , single header value under the given name .
* { @inheritDoc }
* @param headerName the header name
* @since 7 . 0
* @param headerValue the header value
* @throws UnsupportedOperationException if adding headers is not supported
* @see # put ( String , List )
* @see # add ( String , String )
* /
* /
@Override
public void addAll ( String headerName , List < ? extends String > headerValues ) {
this . headers . addAll ( headerName , headerValues ) ;
}
@Override
@Override
public void set ( String headerName , @Nullable String headerValue ) {
public void set ( String headerName , @Nullable String headerValue ) {
this . headers . set ( headerName , headerValue ) ;
this . headers . set ( headerName , headerValue ) ;
@ -230,16 +231,32 @@ public class WebSocketHttpHeaders extends HttpHeaders {
return this . headers . toSingleValueMap ( ) ;
return this . headers . toSingleValueMap ( ) ;
}
}
// Map implementation
/ * *
* { @inheritDoc }
* @since 7 . 0
* @deprecated in favor of { @link # toSingleValueMap ( ) } which performs a copy but
* ensures that collection - iterating methods like { @code entrySet ( ) } are
* case - insensitive
* /
@Override
@Override
public int size ( ) {
@Deprecated ( since = "7.0" , forRemoval = true )
return this . headers . size ( ) ;
@SuppressWarnings ( "removal" )
public Map < String , String > asSingleValueMap ( ) {
return this . headers . asSingleValueMap ( ) ;
}
}
/ * *
* { @inheritDoc }
* @since 7 . 0
* @deprecated This method is provided for backward compatibility with APIs
* that would only accept maps . Generally avoid using HttpHeaders as a Map
* or MultiValueMap .
* /
@Override
@Override
public boolean isEmpty ( ) {
@Deprecated ( since = "7.0" , forRemoval = true )
return this . headers . isEmpty ( ) ;
@SuppressWarnings ( "removal" )
public MultiValueMap < String , String > asMultiValueMap ( ) {
return this . headers . asMultiValueMap ( ) ;
}
}
@Override
@Override
@ -248,13 +265,13 @@ public class WebSocketHttpHeaders extends HttpHeaders {
}
}
@Override
@Override
public @Nullable List < String > get ( String headerName ) {
public boolean isEmpty ( ) {
return this . headers . get ( headerName ) ;
return this . headers . isEmpty ( ) ;
}
}
@Override
@Override
public @Nullable List < String > put ( String key , List < String > value ) {
public int size ( ) {
return this . headers . put ( key , value ) ;
return this . headers . size ( ) ;
}
}
@Override
@Override
@ -262,16 +279,6 @@ public class WebSocketHttpHeaders extends HttpHeaders {
return this . headers . remove ( key ) ;
return this . headers . remove ( key ) ;
}
}
@Override
public void putAll ( HttpHeaders headers ) {
this . headers . putAll ( headers ) ;
}
@Override
public void putAll ( Map < ? extends String , ? extends List < String > > m ) {
this . headers . putAll ( m ) ;
}
@Override
@Override
public void clear ( ) {
public void clear ( ) {
this . headers . clear ( ) ;
this . headers . clear ( ) ;
@ -287,17 +294,6 @@ public class WebSocketHttpHeaders extends HttpHeaders {
return this . headers . headerSet ( ) ;
return this . headers . headerSet ( ) ;
}
}
@Override
public void forEach ( BiConsumer < ? super String , ? super List < String > > action ) {
this . headers . forEach ( action ) ;
}
@Override
public @Nullable List < String > putIfAbsent ( String headerName , List < String > headerValues ) {
return this . headers . putIfAbsent ( headerName , headerValues ) ;
}
@Override
@Override
public boolean equals ( @Nullable Object other ) {
public boolean equals ( @Nullable Object other ) {
return ( this = = other | | ( other instanceof WebSocketHttpHeaders that & &
return ( this = = other | | ( other instanceof WebSocketHttpHeaders that & &