33
33
import io .helidon .common .socket .HelidonSocket ;
34
34
import io .helidon .common .socket .PeerInfo ;
35
35
import io .helidon .common .socket .PlainSocket ;
36
+ import io .helidon .common .socket .SocketOptions ;
36
37
import io .helidon .common .socket .SocketWriter ;
37
38
import io .helidon .common .socket .TlsSocket ;
38
39
import io .helidon .common .task .InterruptableTask ;
@@ -64,11 +65,13 @@ class ConnectionHandler implements InterruptableTask<Void>, ConnectionContext {
64
65
private final String serverChannelId ;
65
66
private final Router router ;
66
67
private final Tls tls ;
68
+ private final SocketOptions connectionOptions ;
67
69
68
70
private ServerConnection connection ;
69
71
private HelidonSocket helidonSocket ;
70
72
private DataReader reader ;
71
73
private SocketWriter writer ;
74
+ private ProxyProtocolData proxyProtocolData ;
72
75
73
76
ConnectionHandler (ListenerContext listenerContext ,
74
77
Semaphore connectionSemaphore ,
@@ -78,7 +81,8 @@ class ConnectionHandler implements InterruptableTask<Void>, ConnectionContext {
78
81
Socket socket ,
79
82
String serverChannelId ,
80
83
Router router ,
81
- Tls tls ) {
84
+ Tls tls ,
85
+ SocketOptions connectionOptions ) {
82
86
this .listenerContext = listenerContext ;
83
87
this .connectionSemaphore = connectionSemaphore ;
84
88
this .requestSemaphore = requestSemaphore ;
@@ -89,6 +93,7 @@ class ConnectionHandler implements InterruptableTask<Void>, ConnectionContext {
89
93
this .serverChannelId = serverChannelId ;
90
94
this .router = router ;
91
95
this .tls = tls ;
96
+ this .connectionOptions = connectionOptions ;
92
97
}
93
98
94
99
@ Override
@@ -100,6 +105,12 @@ public boolean canInterrupt() {
100
105
public final void run () {
101
106
String channelId = "0x" + HexFormat .of ().toHexDigits (System .identityHashCode (socket ));
102
107
108
+ // proxy protocol before SSL handshake
109
+ if (connectionOptions .enableProxyProtocol ()) {
110
+ ProxyProtocolHandler handler = new ProxyProtocolHandler (socket , channelId );
111
+ proxyProtocolData = handler .get ();
112
+ }
113
+
103
114
// handle SSL and init helidonSocket, reader and writer
104
115
try {
105
116
if (tls .enabled ()) {
@@ -226,6 +237,11 @@ public Router router() {
226
237
return router ;
227
238
}
228
239
240
+ @ Override
241
+ public ProxyProtocolData proxyProtocolData () {
242
+ return proxyProtocolData ;
243
+ }
244
+
229
245
private ServerConnection identifyConnection () {
230
246
try {
231
247
reader .ensureAvailable ();
0 commit comments