Skip to content

Commit 88c19c0

Browse files
committed
HTTPCLIENT-2386: Classic transport to use connect timeout as a default if TLS timeout has not been explicitly set
1 parent da4d9a4 commit 88c19c0

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.apache.hc.client5.http.SchemePortResolver;
4242
import org.apache.hc.client5.http.SystemDefaultDnsResolver;
4343
import org.apache.hc.client5.http.UnsupportedSchemeException;
44+
import org.apache.hc.client5.http.config.TlsConfig;
4445
import org.apache.hc.client5.http.impl.ConnPoolSupport;
4546
import org.apache.hc.client5.http.impl.DefaultSchemePortResolver;
4647
import org.apache.hc.client5.http.io.DetachedSocketFactory;
@@ -225,6 +226,11 @@ public void connect(
225226
if (LOG.isDebugEnabled()) {
226227
LOG.debug("{} {} upgrading to TLS", ConnPoolSupport.getId(conn), tlsName);
227228
}
229+
final TlsConfig tlsConfig = attachment instanceof TlsConfig ? (TlsConfig) attachment : TlsConfig.DEFAULT;
230+
final Timeout handshakeTimeout = tlsConfig.getHandshakeTimeout() != null ? tlsConfig.getHandshakeTimeout() : connectTimeout;
231+
if (handshakeTimeout != null) {
232+
socket.setSoTimeout(handshakeTimeout.toMillisecondsIntBound());
233+
}
228234
final SSLSocket sslSocket = tlsSocketStrategy.upgrade(socket, tlsName.getHostName(), tlsName.getPort(), attachment, context);
229235
conn.bind(sslSocket, socket);
230236
onAfterTlsHandshake(context, endpointHost);

httpclient5/src/main/java/org/apache/hc/client5/http/ssl/AbstractClientTlsStrategy.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,6 @@ private void executeHandshake(
220220
final SSLSocket upgradedSocket,
221221
final String target,
222222
final Object attachment) throws IOException {
223-
final TlsConfig tlsConfig = attachment instanceof TlsConfig ? (TlsConfig) attachment : TlsConfig.DEFAULT;
224-
225223
final SSLParameters sslParameters = upgradedSocket.getSSLParameters();
226224
if (supportedProtocols != null) {
227225
sslParameters.setProtocols(supportedProtocols);
@@ -238,17 +236,11 @@ private void executeHandshake(
238236
}
239237
upgradedSocket.setSSLParameters(sslParameters);
240238

241-
final Timeout handshakeTimeout = tlsConfig.getHandshakeTimeout();
242-
if (handshakeTimeout != null) {
243-
upgradedSocket.setSoTimeout(handshakeTimeout.toMillisecondsIntBound());
244-
}
245-
246239
initializeSocket(upgradedSocket);
247240

248241
if (LOG.isDebugEnabled()) {
249242
LOG.debug("Enabled protocols: {}", (Object) upgradedSocket.getEnabledProtocols());
250243
LOG.debug("Enabled cipher suites: {}", (Object) upgradedSocket.getEnabledCipherSuites());
251-
LOG.debug("Starting handshake ({})", handshakeTimeout);
252244
}
253245
upgradedSocket.startHandshake();
254246
verifySession(target, upgradedSocket.getSession());

0 commit comments

Comments
 (0)