From 4695041df4af8a4f2d9d0c50bc70439aeb8a05db Mon Sep 17 00:00:00 2001 From: Alen Turkovic Date: Wed, 4 Jan 2023 15:36:42 +0100 Subject: [PATCH] Pass HttpContext to SSLConnectionSocketFactory#prepareSocket method (#404) --- .../http/ssl/SSLConnectionSocketFactory.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java index 03a7aa6a5..cf08329f2 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/ssl/SSLConnectionSocketFactory.java @@ -178,6 +178,13 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor this.tlsSessionValidator = new TlsSessionValidator(LOG); } + /** + * @deprecated Use {@link #prepareSocket(SSLSocket, HttpContext)} + */ + @Deprecated + protected void prepareSocket(final SSLSocket socket) throws IOException { + } + /** * Performs any custom initialization for a newly created SSLSocket * (before the SSL handshake happens). @@ -186,7 +193,9 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor * call {@link javax.net.ssl.SSLSocket#setEnabledCipherSuites(String[])}. * @throws IOException may be thrown if overridden */ - protected void prepareSocket(final SSLSocket socket) throws IOException { + @SuppressWarnings("deprecation") + protected void prepareSocket(final SSLSocket socket, final HttpContext context) throws IOException { + prepareSocket(socket); } @Override @@ -245,7 +254,7 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor // Setup SSL layering if necessary if (sock instanceof SSLSocket) { final SSLSocket sslsock = (SSLSocket) sock; - executeHandshake(sslsock, host.getHostName(), attachment); + executeHandshake(sslsock, host.getHostName(), attachment, context); return sock; } return createLayeredSocket(sock, host.getHostName(), remoteAddress.getPort(), attachment, context); @@ -272,11 +281,15 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor target, port, true); - executeHandshake(sslsock, target, attachment); + executeHandshake(sslsock, target, attachment, context); return sslsock; } - private void executeHandshake(final SSLSocket sslsock, final String target, final Object attachment) throws IOException { + private void executeHandshake( + final SSLSocket sslsock, + final String target, + final Object attachment, + final HttpContext context) throws IOException { final TlsConfig tlsConfig = attachment instanceof TlsConfig ? (TlsConfig) attachment : TlsConfig.DEFAULT; if (supportedProtocols != null) { sslsock.setEnabledProtocols(supportedProtocols); @@ -293,7 +306,7 @@ public class SSLConnectionSocketFactory implements LayeredConnectionSocketFactor sslsock.setSoTimeout(handshakeTimeout.toMillisecondsIntBound()); } - prepareSocket(sslsock); + prepareSocket(sslsock, context); if (LOG.isDebugEnabled()) { LOG.debug("Enabled protocols: {}", (Object) sslsock.getEnabledProtocols());