15
15
*/
16
16
package org .asynchttpclient .providers .netty .channel ;
17
17
18
+ import static org .asynchttpclient .providers .netty .handler .Processor .newHttpProcessor ;
19
+ import static org .asynchttpclient .providers .netty .handler .Processor .newWsProcessor ;
18
20
import static org .asynchttpclient .providers .netty .util .HttpUtil .WEBSOCKET ;
19
21
import static org .asynchttpclient .providers .netty .util .HttpUtil .isSecure ;
20
22
import static org .asynchttpclient .providers .netty .util .HttpUtil .isWebSocket ;
21
- import static org .asynchttpclient .providers .netty .handler .Processor .newHttpProcessor ;
22
- import static org .asynchttpclient .providers .netty .handler .Processor .newWsProcessor ;
23
23
24
24
import org .asynchttpclient .AsyncHandler ;
25
25
import org .asynchttpclient .AsyncHttpClientConfig ;
@@ -202,20 +202,26 @@ private Timer newNettyTimer() {
202
202
return nettyTimer ;
203
203
}
204
204
205
- private SSLEngine createSSLEngine ( ) throws IOException , GeneralSecurityException {
205
+ public SslHandler createSslHandler ( String peerHost , int peerPort ) throws IOException , GeneralSecurityException {
206
206
207
+ SSLEngine sslEngine = null ;
207
208
if (nettyProviderConfig .getSslEngineFactory () != null ) {
208
- return nettyProviderConfig .getSslEngineFactory ().newSSLEngine ();
209
+ sslEngine = nettyProviderConfig .getSslEngineFactory ().newSSLEngine ();
209
210
210
211
} else {
211
212
SSLContext sslContext = config .getSSLContext ();
212
213
if (sslContext == null )
213
214
sslContext = SslUtils .getInstance ().getSSLContext (config .isAcceptAnyCertificate ());
214
215
215
- SSLEngine sslEngine = sslContext .createSSLEngine ();
216
+ sslEngine = sslContext .createSSLEngine (peerHost , peerPort );
216
217
sslEngine .setUseClientMode (true );
217
- return sslEngine ;
218
218
}
219
+
220
+ SslHandler sslHandler = new SslHandler (sslEngine );
221
+ if (handshakeTimeoutInMillis > 0 )
222
+ sslHandler .setHandshakeTimeoutMillis (handshakeTimeoutInMillis );
223
+
224
+ return sslHandler ;
219
225
}
220
226
221
227
public void configureProcessor (NettyRequestSender requestSender , AtomicBoolean closed ) {
@@ -258,13 +264,8 @@ protected void initChannel(Channel ch) throws Exception {
258
264
@ Override
259
265
protected void initChannel (Channel ch ) throws Exception {
260
266
261
- SSLEngine sslEngine = createSSLEngine ();
262
- SslHandler sslHandler = new SslHandler (sslEngine );
263
- if (handshakeTimeoutInMillis > 0 )
264
- sslHandler .setHandshakeTimeoutMillis (handshakeTimeoutInMillis );
265
-
266
267
ChannelPipeline pipeline = ch .pipeline ()//
267
- .addLast (SSL_HANDLER , sslHandler ) //
268
+ .addLast (SSL_HANDLER , new SslInitializer ( Channels . this ))
268
269
.addLast (HTTP_HANDLER , newHttpClientCodec ());
269
270
270
271
if (config .isCompressionEnabled ()) {
@@ -284,7 +285,7 @@ protected void initChannel(Channel ch) throws Exception {
284
285
@ Override
285
286
protected void initChannel (Channel ch ) throws Exception {
286
287
ch .pipeline ()//
287
- .addLast (SSL_HANDLER , new SslHandler ( createSSLEngine () ))//
288
+ .addLast (SSL_HANDLER , new SslInitializer ( Channels . this ))//
288
289
.addLast (HTTP_HANDLER , newHttpClientCodec ())//
289
290
.addLast (WS_PROCESSOR , wsProcessor );
290
291
@@ -330,7 +331,7 @@ public void verifyChannelPipeline(ChannelPipeline pipeline, String scheme) throw
330
331
pipeline .remove (SSL_HANDLER );
331
332
332
333
} else if (isSecure )
333
- pipeline .addFirst (SSL_HANDLER , new SslHandler ( createSSLEngine () ));
334
+ pipeline .addFirst (SSL_HANDLER , new SslInitializer ( Channels . this ));
334
335
}
335
336
336
337
protected HttpClientCodec newHttpClientCodec () {
@@ -346,15 +347,15 @@ protected HttpClientCodec newHttpClientCodec() {
346
347
}
347
348
}
348
349
349
- public void upgradeProtocol (ChannelPipeline p , String scheme ) throws IOException , GeneralSecurityException {
350
+ public void upgradeProtocol (ChannelPipeline p , String scheme , String host , int port ) throws IOException , GeneralSecurityException {
350
351
if (p .get (HTTP_HANDLER ) != null ) {
351
352
p .remove (HTTP_HANDLER );
352
353
}
353
354
354
355
if (isSecure (scheme )) {
355
356
if (p .get (SSL_HANDLER ) == null ) {
356
357
p .addFirst (HTTP_HANDLER , newHttpClientCodec ());
357
- p .addFirst (SSL_HANDLER , new SslHandler ( createSSLEngine () ));
358
+ p .addFirst (SSL_HANDLER , createSslHandler ( host , port ));
358
359
} else {
359
360
p .addAfter (SSL_HANDLER , HTTP_HANDLER , newHttpClientCodec ());
360
361
}
0 commit comments