Search in sources :

Example 1 with DefaultKeepAliveStrategy

use of org.asynchttpclient.channel.DefaultKeepAliveStrategy in project incubator-pulsar by apache.

the class BrokerServiceLookupTest method getHttpClient.

private AsyncHttpClient getHttpClient(String version) {
    DefaultAsyncHttpClientConfig.Builder confBuilder = new DefaultAsyncHttpClientConfig.Builder();
    confBuilder.setFollowRedirect(true);
    confBuilder.setUserAgent(version);
    confBuilder.setKeepAliveStrategy(new DefaultKeepAliveStrategy() {

        @Override
        public boolean keepAlive(Request ahcRequest, HttpRequest request, HttpResponse response) {
            // Close connection upon a server error or per HTTP spec
            return (response.status().code() / 100 != 5) && super.keepAlive(ahcRequest, request, response);
        }
    });
    AsyncHttpClientConfig config = confBuilder.build();
    return new DefaultAsyncHttpClient(config);
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultKeepAliveStrategy(org.asynchttpclient.channel.DefaultKeepAliveStrategy) BoundRequestBuilder(org.asynchttpclient.BoundRequestBuilder) Request(org.asynchttpclient.Request) HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) HttpResponse(io.netty.handler.codec.http.HttpResponse) AsyncHttpClientConfig(org.asynchttpclient.AsyncHttpClientConfig) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) DefaultAsyncHttpClient(org.asynchttpclient.DefaultAsyncHttpClient)

Aggregations

HttpRequest (io.netty.handler.codec.http.HttpRequest)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 AsyncHttpClientConfig (org.asynchttpclient.AsyncHttpClientConfig)1 BoundRequestBuilder (org.asynchttpclient.BoundRequestBuilder)1 DefaultAsyncHttpClient (org.asynchttpclient.DefaultAsyncHttpClient)1 DefaultAsyncHttpClientConfig (org.asynchttpclient.DefaultAsyncHttpClientConfig)1 Request (org.asynchttpclient.Request)1 DefaultKeepAliveStrategy (org.asynchttpclient.channel.DefaultKeepAliveStrategy)1