Example usage for org.apache.http.nio.client HttpAsyncExchangeHandler keepAlive

List of usage examples for org.apache.http.nio.client HttpAsyncExchangeHandler keepAlive

Introduction

In this page you can find the example usage for org.apache.http.nio.client HttpAsyncExchangeHandler keepAlive.

Prototype

boolean keepAlive(HttpResponse response);

Source Link

Usage

From source file:org.apache.http.impl.nio.client.NHttpClientProtocolHandler.java

private void processResponse(final NHttpClientConnection conn, final HttpExchange httpexchange,
        final HttpAsyncExchangeHandler<?> handler) throws IOException {
    if (!httpexchange.isValid()) {
        conn.close();//from   w ww .  ja v  a 2s.  c o  m
    }
    HttpRequest request = httpexchange.getRequest();
    HttpResponse response = httpexchange.getResponse();

    String method = request.getRequestLine().getMethod();
    int status = response.getStatusLine().getStatusCode();
    if (method.equalsIgnoreCase("CONNECT") && status == HttpStatus.SC_OK) {
        this.log.debug("CONNECT method succeeded");
        conn.resetInput();
    } else {
        if (!handler.keepAlive(response)) {
            conn.close();
        }
    }
    if (this.log.isDebugEnabled()) {
        this.log.debug("Response processed " + formatState(conn, httpexchange));
    }
    handler.responseCompleted();
    httpexchange.reset();
}