From 19545751ca8fe780c693f8e00737ca51b0d6f888 Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Mon, 20 May 2019 11:12:10 -0700 Subject: [PATCH] Restore the ApacheHttpRequest implementation. (#641) The RequestConfig class is an API from the newer Apache HttpClient 4.5.x clients. --- .../client/http/apache/ApacheHttpRequest.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/google-http-client/src/main/java/com/google/api/client/http/apache/ApacheHttpRequest.java b/google-http-client/src/main/java/com/google/api/client/http/apache/ApacheHttpRequest.java index 230d9b0f5..b31b20594 100644 --- a/google-http-client/src/main/java/com/google/api/client/http/apache/ApacheHttpRequest.java +++ b/google-http-client/src/main/java/com/google/api/client/http/apache/ApacheHttpRequest.java @@ -20,21 +20,22 @@ import java.io.IOException; import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.client.HttpClient; -import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.conn.params.ConnManagerParams; +import org.apache.http.params.HttpConnectionParams; +import org.apache.http.params.HttpParams; -/** @author Yaniv Inbar */ +/** + * @author Yaniv Inbar + */ final class ApacheHttpRequest extends LowLevelHttpRequest { private final HttpClient httpClient; private final HttpRequestBase request; - private RequestConfig.Builder requestConfig; - ApacheHttpRequest(HttpClient httpClient, HttpRequestBase request) { this.httpClient = httpClient; this.request = request; - this.requestConfig = RequestConfig.custom().setRedirectsEnabled(false); } @Override @@ -44,14 +45,16 @@ public void addHeader(String name, String value) { @Override public void setTimeout(int connectTimeout, int readTimeout) throws IOException { - requestConfig.setConnectionRequestTimeout(connectTimeout).setSocketTimeout(readTimeout); + HttpParams params = request.getParams(); + ConnManagerParams.setTimeout(params, connectTimeout); + HttpConnectionParams.setConnectionTimeout(params, connectTimeout); + HttpConnectionParams.setSoTimeout(params, readTimeout); } @Override public LowLevelHttpResponse execute() throws IOException { if (getStreamingContent() != null) { - Preconditions.checkArgument( - request instanceof HttpEntityEnclosingRequest, + Preconditions.checkArgument(request instanceof HttpEntityEnclosingRequest, "Apache HTTP client does not support %s requests with content.", request.getRequestLine().getMethod()); ContentEntity entity = new ContentEntity(getContentLength(), getStreamingContent()); @@ -59,7 +62,6 @@ public LowLevelHttpResponse execute() throws IOException { entity.setContentType(getContentType()); ((HttpEntityEnclosingRequest) request).setEntity(entity); } - request.setConfig(requestConfig.build()); return new ApacheHttpResponse(request, httpClient.execute(request)); } }