if (config.getKeyStorePath() != null) {
sslContextFactory.setKeyStorePath(config.getKeyStorePath());
sslContextFactory.setKeyStorePassword(config.getKeyStorePassword());
}
HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setMaxConnectionsPerDestination(config.getMaxConnectionsPerServer());
// disable cookies
httpClient.setCookieStore(new HttpCookieStore.Empty());
long idleTimeout = Long.MAX_VALUE;
if (config.getKeepAliveInterval() != null) {
idleTimeout = Math.min(idleTimeout, config.getKeepAliveInterval().toMillis());
}
if (config.getReadTimeout() != null) {
idleTimeout = Math.min(idleTimeout, config.getReadTimeout().toMillis());
}
if (idleTimeout != Long.MAX_VALUE) {
httpClient.setIdleTimeout(idleTimeout);
}
if (config.getConnectTimeout() != null) {
httpClient.setConnectTimeout(config.getConnectTimeout().toMillis());
}
HostAndPort socksProxy = config.getSocksProxy();
if (socksProxy != null) {
httpClient.getProxyConfiguration().getProxies().add(new Socks4Proxy(socksProxy.getHostText(), socksProxy.getPortOrDefault(1080)));
}
return httpClient;
}