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:
@@ -69,7 +69,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory}
|
* Create a new instance of the {@code HttpComponentsClientHttpRequestFactory}
|
||||||
* with a default {@link HttpClient}.
|
* with a default {@link HttpClient} based on system properties.
|
||||||
*/
|
*/
|
||||||
public HttpComponentsClientHttpRequestFactory() {
|
public HttpComponentsClientHttpRequestFactory() {
|
||||||
this.httpClient = HttpClients.createSystem();
|
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.
|
* A timeout value of 0 specifies an infinite timeout.
|
||||||
* <p>Additional properties can be configured by specifying a
|
* <p>Additional properties can be configured by specifying a
|
||||||
* {@link RequestConfig} instance on a custom {@link HttpClient}.
|
* {@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
|
* @param timeout the timeout value in milliseconds
|
||||||
* @see RequestConfig#getConnectTimeout()
|
* @see RequestConfig#getConnectTimeout()
|
||||||
|
* @see org.apache.http.config.SocketConfig#getSoTimeout
|
||||||
*/
|
*/
|
||||||
public void setConnectTimeout(int timeout) {
|
public void setConnectTimeout(int timeout) {
|
||||||
Assert.isTrue(timeout >= 0, "Timeout must be a non-negative value");
|
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
|
* Set the timeout in milliseconds used when requesting a connection
|
||||||
* manager using the underlying HttpClient.
|
* from the connection manager using the underlying {@link RequestConfig}.
|
||||||
* A timeout value of 0 specifies an infinite timeout.
|
* A timeout value of 0 specifies an infinite timeout.
|
||||||
* <p>Additional properties can be configured by specifying a
|
* <p>Additional properties can be configured by specifying a
|
||||||
* {@link RequestConfig} instance on a custom {@link HttpClient}.
|
* {@link RequestConfig} instance on a custom {@link HttpClient}.
|
||||||
@@ -125,11 +130,12 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest
|
|||||||
* @see RequestConfig#getConnectionRequestTimeout()
|
* @see RequestConfig#getConnectionRequestTimeout()
|
||||||
*/
|
*/
|
||||||
public void setConnectionRequestTimeout(int connectionRequestTimeout) {
|
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.
|
* A timeout value of 0 specifies an infinite timeout.
|
||||||
* <p>Additional properties can be configured by specifying a
|
* <p>Additional properties can be configured by specifying a
|
||||||
* {@link RequestConfig} instance on a custom {@link HttpClient}.
|
* {@link RequestConfig} instance on a custom {@link HttpClient}.
|
||||||
|
|||||||
Reference in New Issue
Block a user