if (fact.getHopCount() <= 1) return UNREACHABLE; if (!plan.getTargetHost().equals(fact.getTargetHost())) return UNREACHABLE; final int phc = plan.getHopCount(); final int fhc = fact.getHopCount(); if (phc < fhc) return UNREACHABLE; if (!plan.getHopTarget(i).equals(fact.getHopTarget(i))) return UNREACHABLE; if ((fact.isTunnelled() && !plan.isTunnelled()) || (fact.isLayered() && !plan.isLayered())) return UNREACHABLE; if (plan.isTunnelled() && !fact.isTunnelled()) return TUNNEL_TARGET; if (plan.isLayered() && !fact.isLayered()) return LAYER_PROTOCOL; if (plan.isSecure() != fact.isSecure()) return UNREACHABLE;
/** * Determines the next step to establish a direct connection. * * @param plan the planned route * @param fact the currently established route * * @return one of the constants defined in this class, indicating * either the next step to perform, or success, or failure */ protected int directStep(RouteInfo plan, RouteInfo fact) { if (fact.getHopCount() > 1) return UNREACHABLE; if (!plan.getTargetHost().equals(fact.getTargetHost())) return UNREACHABLE; // If the security is too low, we could now suggest to layer // a secure protocol on the direct connection. Layering on direct // connections has not been supported in HttpClient 3.x, we don't // consider it here until there is a real-life use case for it. // Should we tolerate if security is better than planned? // (plan.isSecure() && !fact.isSecure()) if (plan.isSecure() != fact.isSecure()) return UNREACHABLE; // Local address has to match only if the plan specifies one. if ((plan.getLocalAddress() != null) && !plan.getLocalAddress().equals(fact.getLocalAddress()) ) return UNREACHABLE; return COMPLETE; }
public static URI rewriteURIForRoute(final URI uri, final RouteInfo route) throws URISyntaxException { if (uri == null) { return null; } if (route.getProxyHost() != null && !route.isTunnelled()) { // Make sure the request URI is absolute if (!uri.isAbsolute()) { final HttpHost target = route.getTargetHost(); return URIUtils.rewriteURI(uri, target, true); } else { return URIUtils.rewriteURI(uri); } } else { // Make sure the request URI is relative if (uri.isAbsolute()) { return URIUtils.rewriteURI(uri, null, true); } else { return URIUtils.rewriteURI(uri); } } } private InternalURIUtils() {
final RouteInfo route = clientContext.getHttpRoute(); if(route != null) { spn = "HTTP/" + route.getProxyHost().getHostName(); final RouteInfo route = clientContext.getHttpRoute(); if(route != null) { spn = "HTTP/" + route.getTargetHost().getHostName();
int port = targetHost.getPort(); if (port < 0) { port = route.getTargetHost().getPort(); port >= 0 ? port : 0, !TextUtils.isEmpty(path) ? path : "/", route.isSecure());
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; } final HttpClientContext clientContext = HttpClientContext.adapt(context); // Obtain the client connection (required) final RouteInfo route = clientContext.getHttpRoute(); if (route == null) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "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); } } }
/** * Determines the first step to establish a route. * * @param plan the planned route * * @return the first step */ protected int firstStep(RouteInfo plan) { return (plan.getHopCount() > 1) ? CONNECT_PROXY : CONNECT_TARGET; }
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { HttpClientContext clientContext = HttpClientContext.adapt(context); AuthState proxyAuthState = clientContext.getProxyAuthState(); // If there's no auth scheme available yet, try to initialize it preemptively if (proxyAuthState.getAuthScheme() == null) { CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); RouteInfo route = clientContext.getHttpRoute(); if (route == null) { return; } HttpHost proxyHost = route.getProxyHost(); if (proxyHost == null) { return; } Credentials creds = credsProvider.getCredentials( new AuthScope(proxyHost.getHostName(), proxyHost.getPort())); if (creds == null) { return; } proxyAuthState.update(new BasicScheme(ChallengeState.PROXY), creds); } } }
return null; if (route.getProxyHost() != null && !route.isTunnelled()) { final HttpHost target = route.getTargetHost(); return rewriteURI(uri, target, true); } else {
final RouteInfo route = clientContext.getHttpRoute(); if (route != null) { spn = "HTTP/" + route.getProxyHost().getHostName(); } else { final RouteInfo route = clientContext.getHttpRoute(); if (route != null) { spn = "HTTP/" + route.getTargetHost().getHostName(); } else {
int port = targetHost.getPort(); if (port < 0) { port = route.getTargetHost().getPort(); port >= 0 ? port : 0, !TextUtils.isEmpty(path) ? path : "/", route.isSecure());
@Override 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; } 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); } } }
/** * Provides the next step. * * @param plan the planned route * @param fact the currently established route, or * <code>null</code> if nothing is established * * @return one of the constants defined in this class, indicating * either the next step to perform, or success, or failure. * 0 is for success, a negative value for failure. */ public int nextStep(RouteInfo plan, RouteInfo fact) { if (plan == null) { throw new IllegalArgumentException ("Planned route may not be null."); } int step = UNREACHABLE; if ((fact == null) || (fact.getHopCount() < 1)) step = firstStep(plan); else if (plan.getHopCount() > 1) step = proxiedStep(plan, fact); else step = directStep(plan, fact); return step; } // nextStep
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { HttpClientContext clientContext = HttpClientContext.adapt(context); AuthState proxyAuthState = clientContext.getProxyAuthState(); // If there's no auth scheme available yet, try to initialize it preemptively if (proxyAuthState.getAuthScheme() == null) { CredentialsProvider credsProvider = clientContext.getCredentialsProvider(); RouteInfo route = clientContext.getHttpRoute(); if (route == null) { return; } HttpHost proxyHost = route.getProxyHost(); if (proxyHost == null) { return; } Credentials creds = credsProvider.getCredentials( new AuthScope(proxyHost.getHostName(), proxyHost.getPort())); if (creds == null) { return; } proxyAuthState.update(new BasicScheme(ChallengeState.PROXY), creds); } } }
if (fact.getHopCount() <= 1) return UNREACHABLE; if (!plan.getTargetHost().equals(fact.getTargetHost())) return UNREACHABLE; final int phc = plan.getHopCount(); final int fhc = fact.getHopCount(); if (phc < fhc) return UNREACHABLE; if (!plan.getHopTarget(i).equals(fact.getHopTarget(i))) return UNREACHABLE; if ((fact.isTunnelled() && !plan.isTunnelled()) || (fact.isLayered() && !plan.isLayered())) return UNREACHABLE; if (plan.isTunnelled() && !fact.isTunnelled()) return TUNNEL_TARGET; if (plan.isLayered() && !fact.isLayered()) return LAYER_PROTOCOL; if (plan.isSecure() != fact.isSecure()) return UNREACHABLE;
/** * Determines the next step to establish a direct connection. * * @param plan the planned route * @param fact the currently established route * * @return one of the constants defined in this class, indicating * either the next step to perform, or success, or failure */ protected int directStep(RouteInfo plan, RouteInfo fact) { if (fact.getHopCount() > 1) return UNREACHABLE; if (!plan.getTargetHost().equals(fact.getTargetHost())) return UNREACHABLE; // If the security is too low, we could now suggest to layer // a secure protocol on the direct connection. Layering on direct // connections has not been supported in HttpClient 3.x, we don't // consider it here until there is a real-life use case for it. // Should we tolerate if security is better than planned? // (plan.isSecure() && !fact.isSecure()) if (plan.isSecure() != fact.isSecure()) return UNREACHABLE; // Local address has to match only if the plan specifies one. if ((plan.getLocalAddress() != null) && !plan.getLocalAddress().equals(fact.getLocalAddress()) ) return UNREACHABLE; return COMPLETE; }
return null; if (route.getProxyHost() != null && !route.isTunnelled()) { final HttpHost target = route.getTargetHost(); return rewriteURI(uri, target, true); } else {
target = new HttpHost( target.getHostName(), route.getTargetHost().getPort(), target.getSchemeName()); final HttpHost proxy = route.getProxyHost(); final AuthStateHC4 proxyState = clientContext.getProxyAuthState(); if (proxy != null && proxyState != null && proxyState.getState() == AuthProtocolState.UNCHALLENGED) {
int port = targetHost.getPort(); if (port < 0) { port = route.getTargetHost().getPort(); port >= 0 ? port : 0, !TextUtils.isEmpty(path) ? path : "/", route.isSecure());
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; } 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); } } }