/** * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. * {@link #NO_HOST} will be mapped to <code>null</code>, * to allow unsetting in a hierarchy. * * @param params the parameters in which to look up * * @return the default proxy set in the argument parameters, or * <code>null</code> if not set */ public static HttpHost getDefaultProxy(HttpParams params) { if (params == null) { throw new IllegalArgumentException("Parameters must not be null."); } HttpHost proxy = (HttpHost) params.getParameter(DEFAULT_PROXY); if ((proxy != null) && NO_HOST.equals(proxy)) { // value is explicitly unset proxy = null; } return proxy; }
/** * 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; }
if (proxy == null) { proxy = determineProxy(target, request, context); } else if (ConnRouteParams.NO_HOST.equals(proxy)) {
if (!route.getTargetHost().equals(newTarget)) { targetAuthState.invalidate(); AuthScheme authScheme = proxyAuthState.getAuthScheme();
@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != getClass()) { return false; } Node other = (Node) obj; return host.equals(other.host) && Objects.equals(boundHosts, other.boundHosts) && Objects.equals(name, other.name) && Objects.equals(version, other.version) && Objects.equals(roles, other.roles) && Objects.equals(attributes, other.attributes); }
@Override public boolean equals(Object obj) { if (obj instanceof Olingo2Configuration) { Olingo2Configuration other = (Olingo2Configuration) obj; return serviceUri == null ? other.serviceUri == null : serviceUri.equals(other.serviceUri) && contentType == null ? other.contentType == null : contentType.equals(other.contentType) && httpHeaders == null ? other.httpHeaders == null : httpHeaders.equals(other.httpHeaders) && connectTimeout == other.connectTimeout && socketTimeout == other.socketTimeout && proxy == null ? other.proxy == null : proxy.equals(other.proxy) && sslContextParameters == null ? other.sslContextParameters == null : sslContextParameters.equals(other.sslContextParameters) && httpAsyncClientBuilder == null ? other.httpAsyncClientBuilder == null : httpAsyncClientBuilder.equals(other.httpAsyncClientBuilder) && httpClientBuilder == null ? other.httpClientBuilder == null : httpClientBuilder.equals(other.httpClientBuilder); } return false; } }
@Override public boolean equals(Object obj) { if (obj instanceof Olingo2Configuration) { Olingo2Configuration other = (Olingo2Configuration) obj; return serviceUri == null ? other.serviceUri == null : serviceUri.equals(other.serviceUri) && contentType == null ? other.contentType == null : contentType.equals(other.contentType) && httpHeaders == null ? other.httpHeaders == null : httpHeaders.equals(other.httpHeaders) && connectTimeout == other.connectTimeout && socketTimeout == other.socketTimeout && proxy == null ? other.proxy == null : proxy.equals(other.proxy) && sslContextParameters == null ? other.sslContextParameters == null : sslContextParameters.equals(other.sslContextParameters) && httpAsyncClientBuilder == null ? other.httpAsyncClientBuilder == null : httpAsyncClientBuilder.equals(other.httpAsyncClientBuilder); } return false; } }
HttpHost myproxy = new HttpHost("myproxy", 8080) CloseableHttpClient client = HttpClientBuilder.create() .setProxy(myproxy) .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy() { @Override public boolean isAuthenticationRequested(HttpHost authhost, HttpResponse response, HttpContext context) { if (myproxy.equals(authhost)) { context.setAttribute("proxy.status", response.getStatusLine()); } return super.isAuthenticationRequested(authhost, response, context); } }) .build(); HttpClientContext context = HttpClientContext.create(); HttpGet get = new HttpGet("https://httpbin.org/"); try (CloseableHttpResponse response = client.execute(get, context)) { EntityUtils.consume(response.getEntity()); } StatusLine proxyStatus = context.getAttribute("proxy.status", StatusLine.class); System.out.println("Proxy said " + proxyStatus);
/** * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. * {@link #NO_HOST} will be mapped to <code>null</code>, * to allow unsetting in a hierarchy. * * @param params the parameters in which to look up * * @return the default proxy set in the argument parameters, or * <code>null</code> if not set */ public static HttpHost getDefaultProxy(HttpParams params) { if (params == null) { throw new IllegalArgumentException("Parameters must not be null."); } HttpHost proxy = (HttpHost) params.getParameter(DEFAULT_PROXY); if ((proxy != null) && NO_HOST.equals(proxy)) { // value is explicitly unset proxy = null; } return proxy; }
/** * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. * {@link #NO_HOST} will be mapped to <code>null</code>, * to allow unsetting in a hierarchy. * * @param params the parameters in which to look up * * @return the default proxy set in the argument parameters, or * <code>null</code> if not set */ public static HttpHost getDefaultProxy(HttpParams params) { if (params == null) { throw new IllegalArgumentException("Parameters must not be null."); } HttpHost proxy = (HttpHost) params.getParameter(DEFAULT_PROXY); if ((proxy != null) && NO_HOST.equals(proxy)) { // value is explicitly unset proxy = null; } return proxy; }
@Override public void process(PoolEntry<HttpHost, NHttpClientConnection> entry) { if (entry.getRoute().equals(host)) { entry.updateExpiry(0, TimeUnit.MILLISECONDS); } } });
@Override public void process(PoolEntry<HttpHost, NHttpClientConnection> entry) { if (entry.getRoute().equals(host)) { entry.updateExpiry(0, TimeUnit.MILLISECONDS); } } });
/** * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. * {@link #NO_HOST} will be mapped to {@code null}, * to allow unsetting in a hierarchy. * * @param params the parameters in which to look up * * @return the default proxy set in the argument parameters, or * {@code null} if not set */ public static HttpHost getDefaultProxy(final HttpParams params) { Args.notNull(params, "Parameters"); HttpHost proxy = (HttpHost) params.getParameter(DEFAULT_PROXY); if ((proxy != null) && NO_HOST.equals(proxy)) { // value is explicitly unset proxy = null; } return proxy; }
/** * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. * {@link #NO_HOST} will be mapped to {@code null}, * to allow unsetting in a hierarchy. * * @param params the parameters in which to look up * * @return the default proxy set in the argument parameters, or * {@code null} if not set */ public static HttpHost getDefaultProxy(final HttpParams params) { Args.notNull(params, "Parameters"); HttpHost proxy = (HttpHost) params.getParameter(DEFAULT_PROXY); if ((proxy != null) && NO_HOST.equals(proxy)) { // value is explicitly unset proxy = null; } return proxy; }
public void handleRedirect(HttpRequestFutureImpl state, HttpContext context) throws IOException { NHttpClientConnection connection = (NHttpClientConnection) context.getAttribute(ExecutionContext.HTTP_CONNECTION); List<HttpRequest> redirects = state.getRedirects(); HttpRequest initial = redirects.size() > 1 ? redirects.get(redirects.size() - 2) : state.getRequest(); HttpRequest redirect = redirects.get(redirects.size() - 1); HttpHost initialHost = getHost(initial); HttpHost redirectHost = getHost(redirect); log.debug("Redirected to {} from {}", redirectHost, initial); if (initialHost.equals(redirectHost) || haveSameAddress(initialHost, redirectHost)) { try { connection.submitRequest(redirect); } catch (HttpException e) { state.failed(e); } } else { state.setActiveConnection(null); connection.close(); ioReactor.connect(new InetSocketAddress(redirectHost.getHostName(), redirectHost.getPort()), null, state, sesionRequestHandler); } }
/** * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. * {@link #NO_HOST} will be mapped to <code>null</code>, * to allow unsetting in a hierarchy. * * @param params the parameters in which to look up * * @return the default proxy set in the argument parameters, or * <code>null</code> if not set */ public static HttpHost getDefaultProxy(final HttpParams params) { Args.notNull(params, "Parameters"); HttpHost proxy = (HttpHost) params.getParameter(DEFAULT_PROXY); if ((proxy != null) && NO_HOST.equals(proxy)) { // value is explicitly unset proxy = null; } return proxy; }
/** * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} * parameter value. * {@link #NO_HOST} will be mapped to {@code null}, * to allow unsetting in a hierarchy. * * @param params the parameters in which to look up * * @return the default proxy set in the argument parameters, or * {@code null} if not set */ public static HttpHost getDefaultProxy(final HttpParams params) { Args.notNull(params, "Parameters"); HttpHost proxy = (HttpHost) params.getParameter(DEFAULT_PROXY); if ((proxy != null) && NO_HOST.equals(proxy)) { // value is explicitly unset proxy = null; } return proxy; }