Classic exec runtime to establish connection automatically if the connection endpoint is disconnected

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1794169 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2017-05-06 18:30:02 +00:00
parent 196ee3363e
commit ecf4e93842
2 changed files with 19 additions and 16 deletions

View File

@ -202,10 +202,6 @@ public final class ConnectExec implements ExecChainHandler {
this.proxyHttpProcessor.process(connect, null, context);
while (response == null) {
if (!execRuntime.isConnected()) {
execRuntime.connect(context);
}
connect.removeHeaders(HttpHeaders.PROXY_AUTHORIZATION);
this.authenticator.addAuthResponse(proxy, ChallengeType.PROXY, connect, proxyAuthExchange, context);

View File

@ -141,22 +141,26 @@ class ExecRuntimeImpl implements ExecRuntime, Cancellable {
return endpoint != null && endpoint.isConnected();
}
private void connectEndpoint(final ConnectionEndpoint endpoint, final HttpClientContext context) throws IOException {
if (cancellableAware != null) {
if (cancellableAware.isCancelled()) {
throw new RequestFailedException("Request aborted");
}
}
final RequestConfig requestConfig = context.getRequestConfig();
final TimeValue connectTimeout = requestConfig.getConnectTimeout();
manager.connect(endpoint, connectTimeout, context);
final TimeValue socketTimeout = requestConfig.getSocketTimeout();
if (socketTimeout.getDuration() >= 0) {
endpoint.setSocketTimeout(socketTimeout.toMillisIntBound());
}
}
@Override
public void connect(final HttpClientContext context) throws IOException {
final ConnectionEndpoint endpoint = ensureValid();
if (!endpoint.isConnected()) {
if (cancellableAware != null) {
if (cancellableAware.isCancelled()) {
throw new RequestFailedException("Request aborted");
}
}
final RequestConfig requestConfig = context.getRequestConfig();
final TimeValue connectTimeout = requestConfig.getConnectTimeout();
manager.connect(endpoint, connectTimeout, context);
final TimeValue socketTimeout = requestConfig.getSocketTimeout();
if (socketTimeout.getDuration() >= 0) {
endpoint.setSocketTimeout(socketTimeout.toMillisIntBound());
}
connectEndpoint(endpoint, context);
}
}
@ -178,6 +182,9 @@ class ExecRuntimeImpl implements ExecRuntime, Cancellable {
@Override
public ClassicHttpResponse execute(final ClassicHttpRequest request, final HttpClientContext context) throws IOException, HttpException {
final ConnectionEndpoint endpoint = ensureValid();
if (!endpoint.isConnected()) {
connectEndpoint(endpoint, context);
}
return endpoint.execute(request, requestExecutor, context);
}