16
16
17
17
package org .springframework .web .reactive .socket ;
18
18
19
+ import java .net .InetSocketAddress ;
19
20
import java .net .URI ;
20
21
import java .security .Principal ;
21
22
import java .util .Collections ;
@@ -46,36 +47,43 @@ public class HandshakeInfo {
46
47
@ Nullable
47
48
private final String protocol ;
48
49
50
+ @ Nullable
51
+ private final InetSocketAddress remoteAddress ;
52
+
49
53
private final Map <String , Object > attributes ;
50
54
51
55
@ Nullable
52
56
private final String logPrefix ;
53
57
54
58
55
59
/**
56
- * Constructor with information about the handshake.
60
+ * Constructor with basic information about the handshake.
57
61
* @param uri the endpoint URL
58
62
* @param headers request headers for server or response headers or client
59
63
* @param principal the principal for the session
60
64
* @param protocol the negotiated sub-protocol (may be {@code null})
61
65
*/
62
66
public HandshakeInfo (URI uri , HttpHeaders headers , Mono <Principal > principal , @ Nullable String protocol ) {
63
- this (uri , headers , principal , protocol , Collections .emptyMap (), null );
67
+ this (uri , headers , principal , protocol , null , Collections .emptyMap (), null );
64
68
}
65
69
66
70
/**
67
- * Constructor with information about the handshake.
71
+ * Constructor targetting server-side use with extra information about the
72
+ * handshake, the remote address, and a pre-existing log prefix for
73
+ * correlation.
68
74
* @param uri the endpoint URL
69
75
* @param headers request headers for server or response headers or client
70
76
* @param principal the principal for the session
71
77
* @param protocol the negotiated sub-protocol (may be {@code null})
78
+ * @param remoteAddress the remote address where the handshake came from
72
79
* @param attributes initial attributes to use for the WebSocket session
73
80
* @param logPrefix log prefix used during the handshake for correlating log
74
81
* messages, if any.
75
82
* @since 5.1
76
83
*/
77
84
public HandshakeInfo (URI uri , HttpHeaders headers , Mono <Principal > principal ,
78
- @ Nullable String protocol , Map <String , Object > attributes , @ Nullable String logPrefix ) {
85
+ @ Nullable String protocol , @ Nullable InetSocketAddress remoteAddress ,
86
+ Map <String , Object > attributes , @ Nullable String logPrefix ) {
79
87
80
88
Assert .notNull (uri , "URI is required" );
81
89
Assert .notNull (headers , "HttpHeaders are required" );
@@ -86,6 +94,7 @@ public HandshakeInfo(URI uri, HttpHeaders headers, Mono<Principal> principal,
86
94
this .headers = headers ;
87
95
this .principalMono = principal ;
88
96
this .protocol = protocol ;
97
+ this .remoteAddress = remoteAddress ;
89
98
this .attributes = attributes ;
90
99
this .logPrefix = logPrefix ;
91
100
}
@@ -123,6 +132,16 @@ public String getSubProtocol() {
123
132
return this .protocol ;
124
133
}
125
134
135
+ /**
136
+ * For a server-side session this is the remote address where the handshake
137
+ * request came from.
138
+ * @since 5.1
139
+ */
140
+ @ Nullable
141
+ public InetSocketAddress getRemoteAddress () {
142
+ return this .remoteAddress ;
143
+ }
144
+
126
145
/**
127
146
* Attributes extracted from the handshake request to be added to the
128
147
* WebSocket session.
0 commit comments