Example usage for org.apache.http.conn.routing RouteInfo isTunnelled

List of usage examples for org.apache.http.conn.routing RouteInfo isTunnelled

Introduction

In this page you can find the example usage for org.apache.http.conn.routing RouteInfo isTunnelled.

Prototype

boolean isTunnelled();

Source Link

Document

Checks whether this route is tunnelled through a proxy.

Usage

From source file:org.apache.http.client.protocol.RequestClientConnControl.java

public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
    Args.notNull(request, "HTTP request");

    final String method = request.getRequestLine().getMethod();
    if (method.equalsIgnoreCase("CONNECT")) {
        request.setHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        return;/*  w ww  .  j a v  a 2 s.c o  m*/
    }

    final HttpClientContext clientContext = HttpClientContext.adapt(context);

    // Obtain the client connection (required)
    final RouteInfo route = clientContext.getHttpRoute();
    if (route == null) {
        this.log.debug("Connection route not set in the context");
        return;
    }

    if (route.getHopCount() == 1 || route.isTunnelled()) {
        if (!request.containsHeader(HTTP.CONN_DIRECTIVE)) {
            request.addHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
    if (route.getHopCount() == 2 && !route.isTunnelled()) {
        if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) {
            request.addHeader(PROXY_CONN_DIRECTIVE, HTTP.CONN_KEEP_ALIVE);
        }
    }
}