use of org.apache.hc.core5.http.protocol.RequestTargetHost in project californium by eclipse.
the class HttpClientFactory method createClient.
/**
* Create the pooled asynchronous http client.
*
* @param config configuration for the http client
* @return asynchronous http client
* @since 3.0 (changed parameter to Configuration)
*/
public static CloseableHttpAsyncClient createClient(Configuration config) {
int connectionIdleSecs = config.getTimeAsInt(Proxy2Config.HTTP_CONNECTION_IDLE_TIMEOUT, TimeUnit.SECONDS);
final CloseableHttpAsyncClient client = HttpAsyncClientBuilder.create().disableCookieManagement().setDefaultRequestConfig(createCustomRequestConfig(config)).setConnectionManager(createPoolingConnManager(config)).setVersionPolicy(HttpVersionPolicy.NEGOTIATE).setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(Timeout.ofSeconds(connectionIdleSecs)).build()).addRequestInterceptorFirst(new RequestConnControl()).addRequestInterceptorFirst(new RequestDate()).addRequestInterceptorFirst(new RequestExpectContinue()).addRequestInterceptorFirst(new RequestTargetHost()).addRequestInterceptorFirst(new RequestUserAgent()).setKeepAliveStrategy(new DefaultConnectionKeepAliveStrategy() {
@Override
public TimeValue getKeepAliveDuration(HttpResponse response, HttpContext context) {
TimeValue keepAlive = super.getKeepAliveDuration(response, context);
if (keepAlive == null || keepAlive.getDuration() < 0) {
// Keep connections alive if a keep-alive value
// has not be explicitly set by the server
keepAlive = KEEP_ALIVE;
}
return keepAlive;
}
}).build();
client.start();
return client;
}
Aggregations