Added #responseTimeout to RequestConfig
This commit is contained in:
parent
b74cb12d44
commit
75ca519314
|
@ -57,6 +57,7 @@ public class RequestConfig implements Cloneable {
|
||||||
private final Collection<String> proxyPreferredAuthSchemes;
|
private final Collection<String> proxyPreferredAuthSchemes;
|
||||||
private final Timeout connectionRequestTimeout;
|
private final Timeout connectionRequestTimeout;
|
||||||
private final Timeout connectTimeout;
|
private final Timeout connectTimeout;
|
||||||
|
private final Timeout responseTimeout;
|
||||||
private final boolean contentCompressionEnabled;
|
private final boolean contentCompressionEnabled;
|
||||||
private final boolean hardCancellationEnabled;
|
private final boolean hardCancellationEnabled;
|
||||||
|
|
||||||
|
@ -65,7 +66,7 @@ public class RequestConfig implements Cloneable {
|
||||||
*/
|
*/
|
||||||
protected RequestConfig() {
|
protected RequestConfig() {
|
||||||
this(false, null, null, false, false, 0, false, null, null,
|
this(false, null, null, false, false, 0, false, null, null,
|
||||||
DEFAULT_CONNECTION_REQUEST_TIMEOUT, DEFAULT_CONNECT_TIMEOUT, false, false);
|
DEFAULT_CONNECTION_REQUEST_TIMEOUT, DEFAULT_CONNECT_TIMEOUT, null, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
RequestConfig(
|
RequestConfig(
|
||||||
|
@ -80,6 +81,7 @@ public class RequestConfig implements Cloneable {
|
||||||
final Collection<String> proxyPreferredAuthSchemes,
|
final Collection<String> proxyPreferredAuthSchemes,
|
||||||
final Timeout connectionRequestTimeout,
|
final Timeout connectionRequestTimeout,
|
||||||
final Timeout connectTimeout,
|
final Timeout connectTimeout,
|
||||||
|
final Timeout responseTimeout,
|
||||||
final boolean contentCompressionEnabled,
|
final boolean contentCompressionEnabled,
|
||||||
final boolean hardCancellationEnabled) {
|
final boolean hardCancellationEnabled) {
|
||||||
super();
|
super();
|
||||||
|
@ -94,6 +96,7 @@ public class RequestConfig implements Cloneable {
|
||||||
this.proxyPreferredAuthSchemes = proxyPreferredAuthSchemes;
|
this.proxyPreferredAuthSchemes = proxyPreferredAuthSchemes;
|
||||||
this.connectionRequestTimeout = connectionRequestTimeout;
|
this.connectionRequestTimeout = connectionRequestTimeout;
|
||||||
this.connectTimeout = connectTimeout;
|
this.connectTimeout = connectTimeout;
|
||||||
|
this.responseTimeout = responseTimeout;
|
||||||
this.contentCompressionEnabled = contentCompressionEnabled;
|
this.contentCompressionEnabled = contentCompressionEnabled;
|
||||||
this.hardCancellationEnabled = hardCancellationEnabled;
|
this.hardCancellationEnabled = hardCancellationEnabled;
|
||||||
}
|
}
|
||||||
|
@ -230,7 +233,6 @@ public class RequestConfig implements Cloneable {
|
||||||
* such as {@code SSL} or {@code TLS} protocol negotiation).
|
* such as {@code SSL} or {@code TLS} protocol negotiation).
|
||||||
* <p>
|
* <p>
|
||||||
* A timeout value of zero is interpreted as an infinite timeout.
|
* A timeout value of zero is interpreted as an infinite timeout.
|
||||||
* A negative value is interpreted as undefined (system default).
|
|
||||||
* </p>
|
* </p>
|
||||||
* <p>
|
* <p>
|
||||||
* Default: 3 minutes
|
* Default: 3 minutes
|
||||||
|
@ -240,6 +242,26 @@ public class RequestConfig implements Cloneable {
|
||||||
return connectTimeout;
|
return connectTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines the timeout until arrival of a response from the opposite
|
||||||
|
* endpoint.
|
||||||
|
* <p>
|
||||||
|
* A timeout value of zero is interpreted as an infinite timeout.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Please note that response timeout may be unsupported by
|
||||||
|
* HTTP transports with message multiplexing.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* Default: {@code null}
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @since 5.0
|
||||||
|
*/
|
||||||
|
public Timeout getResponseTimeout() {
|
||||||
|
return responseTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines whether the target server is requested to compress content.
|
* Determines whether the target server is requested to compress content.
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -343,6 +365,7 @@ public class RequestConfig implements Cloneable {
|
||||||
private Collection<String> proxyPreferredAuthSchemes;
|
private Collection<String> proxyPreferredAuthSchemes;
|
||||||
private Timeout connectionRequestTimeout;
|
private Timeout connectionRequestTimeout;
|
||||||
private Timeout connectTimeout;
|
private Timeout connectTimeout;
|
||||||
|
private Timeout responseTimeout;
|
||||||
private boolean contentCompressionEnabled;
|
private boolean contentCompressionEnabled;
|
||||||
private boolean hardCancellationEnabled;
|
private boolean hardCancellationEnabled;
|
||||||
|
|
||||||
|
@ -422,6 +445,16 @@ public class RequestConfig implements Cloneable {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setResponseTimeout(final Timeout responseTimeout) {
|
||||||
|
this.responseTimeout = responseTimeout;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setResponseTimeout(final long responseTimeout, final TimeUnit timeUnit) {
|
||||||
|
this.responseTimeout = Timeout.of(responseTimeout, timeUnit);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public Builder setContentCompressionEnabled(final boolean contentCompressionEnabled) {
|
public Builder setContentCompressionEnabled(final boolean contentCompressionEnabled) {
|
||||||
this.contentCompressionEnabled = contentCompressionEnabled;
|
this.contentCompressionEnabled = contentCompressionEnabled;
|
||||||
return this;
|
return this;
|
||||||
|
@ -445,6 +478,7 @@ public class RequestConfig implements Cloneable {
|
||||||
proxyPreferredAuthSchemes,
|
proxyPreferredAuthSchemes,
|
||||||
connectionRequestTimeout != null ? connectionRequestTimeout : DEFAULT_CONNECTION_REQUEST_TIMEOUT,
|
connectionRequestTimeout != null ? connectionRequestTimeout : DEFAULT_CONNECTION_REQUEST_TIMEOUT,
|
||||||
connectTimeout != null ? connectTimeout : DEFAULT_CONNECT_TIMEOUT,
|
connectTimeout != null ? connectTimeout : DEFAULT_CONNECT_TIMEOUT,
|
||||||
|
responseTimeout,
|
||||||
contentCompressionEnabled,
|
contentCompressionEnabled,
|
||||||
hardCancellationEnabled);
|
hardCancellationEnabled);
|
||||||
}
|
}
|
||||||
|
|
|
@ -238,6 +238,11 @@ class InternalHttpAsyncExecRuntime implements AsyncExecRuntime {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(ConnPoolSupport.getId(endpoint) + ": executing " + ConnPoolSupport.getId(exchangeHandler));
|
log.debug(ConnPoolSupport.getId(endpoint) + ": executing " + ConnPoolSupport.getId(exchangeHandler));
|
||||||
}
|
}
|
||||||
|
final RequestConfig requestConfig = context.getRequestConfig();
|
||||||
|
final Timeout responseTimeout = requestConfig.getResponseTimeout();
|
||||||
|
if (responseTimeout != null) {
|
||||||
|
endpoint.setSocketTimeout(responseTimeout);
|
||||||
|
}
|
||||||
endpoint.execute(exchangeHandler, context);
|
endpoint.execute(exchangeHandler, context);
|
||||||
if (context.getRequestConfig().isHardCancellationEnabled()) {
|
if (context.getRequestConfig().isHardCancellationEnabled()) {
|
||||||
return new Cancellable() {
|
return new Cancellable() {
|
||||||
|
|
|
@ -265,6 +265,7 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
|
||||||
}
|
}
|
||||||
final Timeout connectionRequestTimeout = requestConfig.getConnectionRequestTimeout();
|
final Timeout connectionRequestTimeout = requestConfig.getConnectionRequestTimeout();
|
||||||
final Timeout connectTimeout = requestConfig.getConnectTimeout();
|
final Timeout connectTimeout = requestConfig.getConnectTimeout();
|
||||||
|
final Timeout responseTimeout = requestConfig.getResponseTimeout();
|
||||||
final HttpHost target = new HttpHost(request.getAuthority(), request.getScheme());
|
final HttpHost target = new HttpHost(request.getAuthority(), request.getScheme());
|
||||||
|
|
||||||
final Future<AsyncConnectionEndpoint> leaseFuture = leaseEndpoint(
|
final Future<AsyncConnectionEndpoint> leaseFuture = leaseEndpoint(
|
||||||
|
@ -393,6 +394,9 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
if (responseTimeout != null) {
|
||||||
|
endpoint.setSocketTimeout(responseTimeout);
|
||||||
|
}
|
||||||
endpoint.execute(internalExchangeHandler, pushHandlerFactory, clientContext);
|
endpoint.execute(internalExchangeHandler, pushHandlerFactory, clientContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -463,6 +467,10 @@ public final class MinimalHttpAsyncClient extends AbstractMinimalHttpAsyncClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSocketTimeout(final Timeout timeout) {
|
||||||
|
connectionEndpoint.setSocketTimeout(timeout);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseAndReuse() {
|
public void releaseAndReuse() {
|
||||||
if (released.compareAndSet(false, true)) {
|
if (released.compareAndSet(false, true)) {
|
||||||
|
|
|
@ -187,6 +187,11 @@ class InternalExecRuntime implements ExecRuntime, Cancellable {
|
||||||
if (!endpoint.isConnected()) {
|
if (!endpoint.isConnected()) {
|
||||||
connectEndpoint(endpoint, context);
|
connectEndpoint(endpoint, context);
|
||||||
}
|
}
|
||||||
|
final RequestConfig requestConfig = context.getRequestConfig();
|
||||||
|
final Timeout responseTimeout = requestConfig.getResponseTimeout();
|
||||||
|
if (responseTimeout != null) {
|
||||||
|
endpoint.setSocketTimeout(responseTimeout);
|
||||||
|
}
|
||||||
return endpoint.execute(request, requestExecutor, context);
|
return endpoint.execute(request, requestExecutor, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue