Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 35d5617

Browse files
author
Cihat Keser
committed
lazy init all variables of HttpClientConfig.Builder
1 parent 41e0223 commit 35d5617

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

jest/src/main/java/io/searchbox/client/config/HttpClientConfig.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ public static class Builder extends ClientConfig.AbstractBuilder<HttpClientConfi
101101
private Map<HttpRoute, Integer> maxTotalConnectionPerRoute = new HashMap<HttpRoute, Integer>();
102102
private CredentialsProvider credentialsProvider;
103103
private LayeredConnectionSocketFactory sslSocketFactory;
104-
private ConnectionSocketFactory plainSocketFactory = PlainConnectionSocketFactory.getSocketFactory();
105-
private HttpRoutePlanner httpRoutePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault());
104+
private ConnectionSocketFactory plainSocketFactory;
105+
private HttpRoutePlanner httpRoutePlanner;
106106
private AuthenticationStrategy proxyAuthenticationStrategy;
107-
private SchemeIOSessionStrategy httpIOSessionStrategy = NoopIOSessionStrategy.INSTANCE;
108-
private SchemeIOSessionStrategy httpsIOSessionStrategy = SSLIOSessionStrategy.getSystemDefaultStrategy();
107+
private SchemeIOSessionStrategy httpIOSessionStrategy;
108+
private SchemeIOSessionStrategy httpsIOSessionStrategy;
109109

110110
public Builder(HttpClientConfig httpClientConfig) {
111111
super(httpClientConfig);
@@ -242,10 +242,22 @@ public Builder proxy(HttpHost proxy, AuthenticationStrategy proxyAuthenticationS
242242
}
243243

244244
public HttpClientConfig build() {
245+
// Lazily initialize if necessary, as the call can be expensive when done eagerly.
245246
if (this.sslSocketFactory == null) {
246-
// Lazily initialize if necessary, as the call can be expensive when done eagerly.
247247
this.sslSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
248248
}
249+
if(this.plainSocketFactory == null) {
250+
this.plainSocketFactory = PlainConnectionSocketFactory.getSocketFactory();
251+
}
252+
if(this.httpRoutePlanner == null) {
253+
this.httpRoutePlanner = new SystemDefaultRoutePlanner(ProxySelector.getDefault());
254+
}
255+
if(this.httpIOSessionStrategy == null) {
256+
this.httpIOSessionStrategy = NoopIOSessionStrategy.INSTANCE;
257+
}
258+
if(this.httpsIOSessionStrategy == null) {
259+
this.httpsIOSessionStrategy = SSLIOSessionStrategy.getSystemDefaultStrategy();
260+
}
249261
return new HttpClientConfig(this);
250262
}
251263

0 commit comments

Comments
 (0)