Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ApacheHttpTransport configuration #717

Merged
merged 2 commits into from
Jun 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ final class ApacheHttpRequest extends LowLevelHttpRequest {

private RequestConfig.Builder requestConfig;

@SuppressWarnings("deprecation")
ApacheHttpRequest(HttpClient httpClient, HttpRequestBase request) {
this.httpClient = httpClient;
this.request = request;
// disable redirects as google-http-client handles redirects
this.requestConfig = RequestConfig.custom().setRedirectsEnabled(false);
this.requestConfig = RequestConfig.custom()
.setRedirectsEnabled(false)
// TODO(chingor): configure in HttpClientBuilder when available
.setStaleConnectionCheckEnabled(false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,14 @@ public static HttpClientBuilder newDefaultHttpClientBuilder() {
.setSndBufSize(8192)
.build();

PoolingHttpClientConnectionManager connectionManager =
new PoolingHttpClientConnectionManager(-1, TimeUnit.MILLISECONDS);
// Disable the stale connection check (previously configured in the HttpConnectionParams
connectionManager.setValidateAfterInactivity(-1);

return HttpClientBuilder.create()
.useSystemProperties()
.setSSLSocketFactory(SSLConnectionSocketFactory.getSocketFactory())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you remove this? By default, it will create and use SSLConnectionSocketFactory.getSocketFactory(). If this is set, I can't set .setSSLContext() or .setSSLHostnameVerifier() as they are overridden in the same manner with setConnectionManager().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... that may not exactly be same when useSystemProperties() is set.

Nonetheless, I think I'm OK either way, since I can explicitly unset the factory by .setSSLSocketFactory(null), so not a big deal.

.setDefaultSocketConfig(socketConfig)
.setMaxConnTotal(200)
.setMaxConnPerRoute(20)
.setConnectionTimeToLive(-1, TimeUnit.MILLISECONDS)
.setRoutePlanner(new SystemDefaultRoutePlanner(ProxySelector.getDefault()))
.setConnectionManager(connectionManager)
.disableRedirectHandling()
.disableAutomaticRetries();
}
Expand Down