2222import java .util .Collections ;
2323import java .util .Map ;
2424
25+ import org .springframework .http .HttpCookie ;
26+ import org .springframework .util .CollectionUtils ;
27+ import org .springframework .util .MultiValueMap ;
2528import reactor .core .publisher .Mono ;
2629
2730import org .springframework .http .HttpHeaders ;
@@ -44,6 +47,8 @@ public class HandshakeInfo {
4447
4548 private final HttpHeaders headers ;
4649
50+ private final MultiValueMap <String , HttpCookie > cookies ;
51+
4752 @ Nullable
4853 private final String protocol ;
4954
@@ -67,6 +72,7 @@ public HandshakeInfo(URI uri, HttpHeaders headers, Mono<Principal> principal, @N
6772 this (uri , headers , principal , protocol , null , Collections .emptyMap (), null );
6873 }
6974
75+
7076 /**
7177 * Constructor targetting server-side use with extra information about the
7278 * handshake, the remote address, and a pre-existing log prefix for
@@ -81,17 +87,39 @@ public HandshakeInfo(URI uri, HttpHeaders headers, Mono<Principal> principal, @N
8187 * messages, if any.
8288 * @since 5.1
8389 */
90+ @ Deprecated
8491 public HandshakeInfo (URI uri , HttpHeaders headers , Mono <Principal > principal ,
85- @ Nullable String protocol , @ Nullable InetSocketAddress remoteAddress ,
86- Map <String , Object > attributes , @ Nullable String logPrefix ) {
92+ @ Nullable String protocol , @ Nullable InetSocketAddress remoteAddress ,
93+ Map <String , Object > attributes , @ Nullable String logPrefix ) {
94+ this (uri , headers , CollectionUtils .toMultiValueMap (Collections .emptyMap ()), principal , protocol , remoteAddress , attributes , logPrefix );
95+ }
8796
97+ /**
98+ * Constructor targetting server-side use with extra information about the
99+ * handshake, the remote address, and a pre-existing log prefix for
100+ * correlation.
101+ * @param uri the endpoint URL
102+ * @param headers request headers for server or response headers or client
103+ * @param cookies request cookies for server
104+ * @param principal the principal for the session
105+ * @param protocol the negotiated sub-protocol (may be {@code null})
106+ * @param remoteAddress the remote address where the handshake came from
107+ * @param attributes initial attributes to use for the WebSocket session
108+ * @param logPrefix log prefix used during the handshake for correlating log
109+ * messages, if any.
110+ * @since 5.4
111+ */
112+ public HandshakeInfo (URI uri , HttpHeaders headers , MultiValueMap <String , HttpCookie > cookies ,
113+ Mono <Principal > principal , @ Nullable String protocol , @ Nullable InetSocketAddress remoteAddress ,
114+ Map <String , Object > attributes , @ Nullable String logPrefix ) {
88115 Assert .notNull (uri , "URI is required" );
89116 Assert .notNull (headers , "HttpHeaders are required" );
90117 Assert .notNull (principal , "Principal is required" );
91118 Assert .notNull (attributes , "'attributes' is required" );
92119
93120 this .uri = uri ;
94121 this .headers = headers ;
122+ this .cookies = cookies ;
95123 this .principalMono = principal ;
96124 this .protocol = protocol ;
97125 this .remoteAddress = remoteAddress ;
@@ -115,6 +143,13 @@ public HttpHeaders getHeaders() {
115143 return this .headers ;
116144 }
117145
146+ /**
147+ * Return the handshake HTTP cookies.
148+ */
149+ public MultiValueMap <String , HttpCookie > getCookies () {
150+ return this .cookies ;
151+ }
152+
118153 /**
119154 * Return the principal associated with the handshake HTTP request.
120155 */
0 commit comments