22
22
import java .util .Collections ;
23
23
import java .util .Map ;
24
24
25
+ import org .springframework .http .HttpCookie ;
26
+ import org .springframework .util .CollectionUtils ;
27
+ import org .springframework .util .MultiValueMap ;
25
28
import reactor .core .publisher .Mono ;
26
29
27
30
import org .springframework .http .HttpHeaders ;
@@ -44,6 +47,8 @@ public class HandshakeInfo {
44
47
45
48
private final HttpHeaders headers ;
46
49
50
+ private final MultiValueMap <String , HttpCookie > cookies ;
51
+
47
52
@ Nullable
48
53
private final String protocol ;
49
54
@@ -67,6 +72,7 @@ public HandshakeInfo(URI uri, HttpHeaders headers, Mono<Principal> principal, @N
67
72
this (uri , headers , principal , protocol , null , Collections .emptyMap (), null );
68
73
}
69
74
75
+
70
76
/**
71
77
* Constructor targetting server-side use with extra information about the
72
78
* 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
81
87
* messages, if any.
82
88
* @since 5.1
83
89
*/
90
+ @ Deprecated
84
91
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
+ }
87
96
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 ) {
88
115
Assert .notNull (uri , "URI is required" );
89
116
Assert .notNull (headers , "HttpHeaders are required" );
90
117
Assert .notNull (principal , "Principal is required" );
91
118
Assert .notNull (attributes , "'attributes' is required" );
92
119
93
120
this .uri = uri ;
94
121
this .headers = headers ;
122
+ this .cookies = cookies ;
95
123
this .principalMono = principal ;
96
124
this .protocol = protocol ;
97
125
this .remoteAddress = remoteAddress ;
@@ -115,6 +143,13 @@ public HttpHeaders getHeaders() {
115
143
return this .headers ;
116
144
}
117
145
146
+ /**
147
+ * Return the handshake HTTP cookies.
148
+ */
149
+ public MultiValueMap <String , HttpCookie > getCookies () {
150
+ return this .cookies ;
151
+ }
152
+
118
153
/**
119
154
* Return the principal associated with the handshake HTTP request.
120
155
*/
0 commit comments