@@ -201,15 +201,18 @@ private Timer newNettyTimer() {
201
201
return nettyTimer ;
202
202
}
203
203
204
- private SSLEngine createSSLEngine () throws IOException , GeneralSecurityException {
205
- SSLEngine sslEngine = config .getSSLEngineFactory ().newSSLEngine ();
204
+ private SSLEngine createSSLEngine (String peerHost , int peerPort ) throws IOException , GeneralSecurityException {
205
+ SSLEngine sslEngine = config .getSSLEngineFactory ().newSSLEngine (peerHost , peerPort );
206
206
if (sslEngine == null ) {
207
- sslEngine = SslUtils .getInstance ().getSSLEngine ();
207
+ sslEngine = SslUtils .getInstance ().getSSLEngine (peerHost , peerPort );
208
208
}
209
209
return sslEngine ;
210
210
}
211
211
212
- public void configureProcessor (NettyRequestSender requestSender , AtomicBoolean closed ) {
212
+ public void configureProcessor (final NettyRequestSender requestSender ,//
213
+ final AtomicBoolean closed ,//
214
+ final String peerHost ,//
215
+ final int peerPort ) {
213
216
214
217
final Processor httpProcessor = newHttpProcessor (config , nettyProviderConfig , requestSender , this , closed );
215
218
wsProcessor = newWsProcessor (config , nettyProviderConfig , requestSender , this , closed );
@@ -249,7 +252,7 @@ protected void initChannel(Channel ch) throws Exception {
249
252
@ Override
250
253
protected void initChannel (Channel ch ) throws Exception {
251
254
252
- SSLEngine sslEngine = createSSLEngine ();
255
+ SSLEngine sslEngine = createSSLEngine (peerHost , peerPort );
253
256
SslHandler sslHandler = new SslHandler (sslEngine );
254
257
if (handshakeTimeoutInMillis > 0 )
255
258
sslHandler .setHandshakeTimeoutMillis (handshakeTimeoutInMillis );
@@ -275,7 +278,7 @@ protected void initChannel(Channel ch) throws Exception {
275
278
@ Override
276
279
protected void initChannel (Channel ch ) throws Exception {
277
280
ch .pipeline ()//
278
- .addLast (SSL_HANDLER , new SslHandler (createSSLEngine ()))//
281
+ .addLast (SSL_HANDLER , new SslHandler (createSSLEngine (peerHost , peerPort )))//
279
282
.addLast (HTTP_HANDLER , newHttpClientCodec ())//
280
283
.addLast (WS_PROCESSOR , wsProcessor );
281
284
@@ -313,15 +316,15 @@ public void close() {
313
316
* Always make sure the channel who got cached support the proper protocol. It could only occurs when a HttpMethod.
314
317
* CONNECT is used against a proxy that requires upgrading from http to https.
315
318
*/
316
- public void verifyChannelPipeline (ChannelPipeline pipeline , String scheme ) throws IOException , GeneralSecurityException {
319
+ public void verifyChannelPipeline (ChannelPipeline pipeline , String scheme , String peerHost , int peerPort ) throws IOException , GeneralSecurityException {
317
320
318
321
boolean isSecure = isSecure (scheme );
319
322
if (pipeline .get (SSL_HANDLER ) != null ) {
320
323
if (!isSecure )
321
324
pipeline .remove (SSL_HANDLER );
322
325
323
326
} else if (isSecure )
324
- pipeline .addFirst (SSL_HANDLER , new SslHandler (createSSLEngine ()));
327
+ pipeline .addFirst (SSL_HANDLER , new SslHandler (createSSLEngine (peerHost , peerPort )));
325
328
}
326
329
327
330
protected HttpClientCodec newHttpClientCodec () {
@@ -337,15 +340,15 @@ protected HttpClientCodec newHttpClientCodec() {
337
340
}
338
341
}
339
342
340
- public void upgradeProtocol (ChannelPipeline p , String scheme ) throws IOException , GeneralSecurityException {
343
+ public void upgradeProtocol (ChannelPipeline p , String scheme , String peerHost , int peerPort ) throws IOException , GeneralSecurityException {
341
344
if (p .get (HTTP_HANDLER ) != null ) {
342
345
p .remove (HTTP_HANDLER );
343
346
}
344
347
345
348
if (isSecure (scheme )) {
346
349
if (p .get (SSL_HANDLER ) == null ) {
347
350
p .addFirst (HTTP_HANDLER , newHttpClientCodec ());
348
- p .addFirst (SSL_HANDLER , new SslHandler (createSSLEngine ()));
351
+ p .addFirst (SSL_HANDLER , new SslHandler (createSSLEngine (peerHost , peerPort )));
349
352
} else {
350
353
p .addAfter (SSL_HANDLER , HTTP_HANDLER , newHttpClientCodec ());
351
354
}
@@ -371,7 +374,7 @@ public Channel pollAndVerifyCachedChannel(URI uri, ProxyServer proxy, Connection
371
374
LOGGER .debug ("Using cached Channel {}\n for uri {}\n " , channel , uri );
372
375
373
376
try {
374
- verifyChannelPipeline (channel .pipeline (), uri .getScheme ());
377
+ verifyChannelPipeline (channel .pipeline (), uri .getScheme (), uri . getHost (), uri . getPort () );
375
378
} catch (Exception ex ) {
376
379
LOGGER .debug (ex .getMessage (), ex );
377
380
}
0 commit comments