Skip to content

Commit

Permalink
Merge pull request searchbox-io#252 from poblish/master
Browse files Browse the repository at this point in the history
Lazily instantiate SSLConnectionSocketFactory to avoid expensive call - fixes searchbox-io#251
  • Loading branch information
Cihat Keser committed Nov 4, 2015
2 parents e8d67de + 857e8d3 commit 41e0223
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static class Builder extends ClientConfig.AbstractBuilder<HttpClientConfi
private Integer defaultMaxTotalConnectionPerRoute;
private Map<HttpRoute, Integer> maxTotalConnectionPerRoute = new HashMap<HttpRoute, Integer>();
private CredentialsProvider credentialsProvider;
private LayeredConnectionSocketFactory sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
private LayeredConnectionSocketFactory sslSocketFactory;
private ConnectionSocketFactory plainSocketFactory = PlainConnectionSocketFactory.getSocketFactory();
private HttpRoutePlanner httpRoutePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault());
private AuthenticationStrategy proxyAuthenticationStrategy;
Expand Down Expand Up @@ -242,6 +242,10 @@ public Builder proxy(HttpHost proxy, AuthenticationStrategy proxyAuthenticationS
}

public HttpClientConfig build() {
if (this.sslSocketFactory == null) {
// Lazily initialize if necessary, as the call can be expensive when done eagerly.
this.sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
}
return new HttpClientConfig(this);
}

Expand Down

0 comments on commit 41e0223

Please sign in to comment.