use of org.apache.hc.client5.http.impl.routing.SystemDefaultRoutePlanner in project gradle-download-task by michel-kraemer.
the class DefaultHttpClientFactory method createHttpClient.
@Override
public CloseableHttpClient createHttpClient(HttpHost httpHost, boolean acceptAnyCertificate, final int retries, Logger logger, boolean quiet) {
HttpClientBuilder builder = HttpClientBuilder.create();
// configure retries
if (retries == 0) {
builder.disableAutomaticRetries();
} else {
// TODO make interval configurable
int maxRetries = retries;
if (retries < 0) {
maxRetries = Integer.MAX_VALUE;
}
builder.setRetryStrategy(new CustomHttpRequestRetryStrategy(maxRetries, TimeValue.ofSeconds(0L), logger, quiet));
}
// configure proxy from system environment
builder.setRoutePlanner(new SystemDefaultRoutePlanner(null));
// accept any certificate if necessary
if ("https".equals(httpHost.getSchemeName()) && acceptAnyCertificate) {
SSLConnectionSocketFactory icsf = getInsecureSSLSocketFactory();
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", icsf).register("http", PlainConnectionSocketFactory.INSTANCE).build();
HttpClientConnectionManager cm = new BasicHttpClientConnectionManager(registry);
builder.setConnectionManager(cm);
}
return builder.build();
}
Aggregations