Document socket timeout config limitations for HttpClient

This commit documents the difference between configuring the socket
timeout on the `RequestConfig` and on the `SocketConfig`.

The first one does not affect timeouts when establishing an SSL
connection or sending a CONNECT request to a proxy. For these use cases,
it is required to configure `SocketConfig` on the `HttpClient` instance
directly.

Issue: SPR-16697
This commit is contained in:
Brian Clozel
2018-04-06 16:35:17 +02:00
parent de3a9560d9
commit 2dde000475

View File

@@ -69,7 +69,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
/**
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory}
* with a default {@link HttpClient}.
* with a default {@link HttpClient} based on system properties.
*/
public HttpComponentsClientHttpRequestFactory() {
this.httpClient = HttpClients.createSystem();
@@ -103,12 +103,17 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
}
/**
* Set the connection timeout for the underlying HttpClient.
* Set the connection timeout for the underlying {@link RequestConfig}.
* A timeout value of 0 specifies an infinite timeout.
* <p>Additional properties can be configured by specifying a
* {@link RequestConfig} instance on a custom {@link HttpClient}.
* <p>This options does not affect connection timeouts for SSL
* handshakes or CONNECT requests; for that, it is required to
* use the {@link org.apache.http.config.SocketConfig} on the
* {@link HttpClient} itself.
* @param timeout the timeout value in milliseconds
* @see RequestConfig#getConnectTimeout()
* @see org.apache.http.config.SocketConfig#getSoTimeout
*/
public void setConnectTimeout(int timeout) {
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
@@ -116,8 +121,8 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
}
/**
* Set the timeout in milliseconds used when requesting a connection from the connection
* manager using the underlying HttpClient.
* Set the timeout in milliseconds used when requesting a connection
* from the connection manager using the underlying {@link RequestConfig}.
* A timeout value of 0 specifies an infinite timeout.
* <p>Additional properties can be configured by specifying a
* {@link RequestConfig} instance on a custom {@link HttpClient}.
@@ -125,11 +130,12 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
* @see RequestConfig#getConnectionRequestTimeout()
*/
public void setConnectionRequestTimeout(int connectionRequestTimeout) {
this.requestConfig = requestConfigBuilder().setConnectionRequestTimeout(connectionRequestTimeout).build();
this.requestConfig = requestConfigBuilder()
.setConnectionRequestTimeout(connectionRequestTimeout).build();
}
/**
* Set the socket read timeout for the underlying HttpClient.
* Set the socket read timeout for the underlying {@link RequestConfig}.
* A timeout value of 0 specifies an infinite timeout.
* <p>Additional properties can be configured by specifying a
* {@link RequestConfig} instance on a custom {@link HttpClient}.