private static String getPartitionId(InetAddress overrideAddress, Request request, ProxyServer proxyServer) { return (overrideAddress != null ? overrideAddress.toString() + "_" : "") + request.getConnectionPoolPartitioning() .getPartitionKey(request.getUri(), proxyServer).toString(); }
/** * @see #avoidProxy(ProxyServer, String) */ public static boolean avoidProxy(final ProxyServer proxyServer, final Request request) { return avoidProxy(proxyServer, request.getUri().getHost()); }
private HttpURLConnection createUrlConnection(Request request) throws IOException, URISyntaxException { ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request); Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm(); Proxy proxy = null; if (proxyServer != null || realm != null) { try { proxy = configureProxyAndAuth(proxyServer, realm); } catch (AuthenticationException e) { throw new IOException(e.getMessage()); } } HttpURLConnection urlConnection = (HttpURLConnection) request.getUri().toJavaNetURI().toURL().openConnection(proxy == null ? Proxy.NO_PROXY : proxy); if (request.getUri().getScheme().equals("https")) { HttpsURLConnection secure = (HttpsURLConnection) urlConnection; SSLContext sslContext; try { sslContext = SslUtils.getInstance().getSSLContext(config); } catch (GeneralSecurityException e) { throw new IOException(e.getMessage()); } secure.setSSLSocketFactory(sslContext.getSocketFactory()); secure.setHostnameVerifier(config.getHostnameVerifier()); } return urlConnection; }
/** * @param config the global config * @param request the request * @return the proxy server to be used for this request (can be null) */ public static ProxyServer getProxyServer(AsyncHttpClientConfig config, Request request) { ProxyServer proxyServer = request.getProxyServer(); if (proxyServer == null) { ProxyServerSelector selector = config.getProxyServerSelector(); if (selector != null) { proxyServer = selector.select(request.getUri()); } } return ProxyUtils.avoidProxy(proxyServer, request) ? null : proxyServer; }
private Future<Response> execute(RequestBuilder rb, BodyConsumer bodyConsumer, ThrowableHandler throwableHandler) throws IOException { if (throwableHandler == null) { throwableHandler = defaultThrowableHandler; } Request request = rb.build(); ProgressAsyncHandler<Response> handler = new BodyConsumerAsyncHandler(bodyConsumer, throwableHandler, errorDocumentBehaviour, request.getUri(), listener); if (resumeEnabled && request.getMethod().equals("GET") && bodyConsumer != null && bodyConsumer instanceof ResumableBodyConsumer) { ResumableBodyConsumer fileBodyConsumer = (ResumableBodyConsumer) bodyConsumer; long length = fileBodyConsumer.getTransferredBytes(); fileBodyConsumer.resume(); handler = new ResumableBodyConsumerAsyncHandler(length, handler); } return asyncHttpClient().executeRequest(request, handler); }
private HttpTransactionContext(final GrizzlyAsyncHttpProvider provider, final Connection connection, final GrizzlyResponseFuture future, final Request ahcRequest) { this.provider = provider; this.connection = connection; this.future = future; this.ahcRequest = ahcRequest; this.proxyServer = ProxyUtils.getProxyServer( provider.getClientConfig(), ahcRequest); redirectsAllowed = provider.getClientConfig().isFollowRedirect(); maxRedirectCount = provider.getClientConfig().getMaxRedirects(); this.requestUri = ahcRequest.getUri(); }
public <T> ListenableFuture<T> sendRequest(final Request request,// final AsyncHandler<T> asyncHandler,// NettyResponseFuture<T> future,// boolean reclaimCache) throws IOException { if (closed.get()) throw new IOException("Closed"); Uri uri = request.getUri(); validateWebSocketRequest(request, uri, asyncHandler); ProxyServer proxyServer = getProxyServer(config, request); boolean resultOfAConnect = future != null && future.getNettyRequest() != null && future.getNettyRequest().getHttpRequest().getMethod() == HttpMethod.CONNECT; boolean useProxy = proxyServer != null && !resultOfAConnect; if (useProxy && useProxyConnect(uri)) // SSL proxy, have to handle CONNECT if (future != null && future.isConnectAllowed()) // CONNECT forced return sendRequestWithCertainForceConnect(request, asyncHandler, future, reclaimCache, uri, proxyServer, true, true); else return sendRequestThroughSslProxy(request, asyncHandler, future, reclaimCache, uri, proxyServer); else return sendRequestWithCertainForceConnect(request, asyncHandler, future, reclaimCache, uri, proxyServer, useProxy, false); }
@Override public void calculateAndAddSignature(Request request, RequestBuilderBase<?> requestBuilder) { String nonce = generateNonce(); long timestamp = generateTimestamp(); String signature = calculateSignature(request.getMethod(), request.getUri(), timestamp, nonce, request.getFormParams(), request.getQueryParams()); String headerValue = constructAuthHeader(signature, nonce, timestamp); requestBuilder.setHeader(HEADER_AUTHORIZATION, headerValue); }
private Realm ntlmChallenge(String wwwAuth, Request request, FluentCaseInsensitiveStringsMap headers, Realm realm, NettyResponseFuture<?> future) throws NTLMEngineException { Uri uri = request.getUri(); if (wwwAuth.equals("NTLM")) { // server replied bare NTLM => we didn't preemptively sent Type1Msg String challengeHeader = NTLMEngine.INSTANCE.generateType1Msg(); addNTLMAuthorizationHeader(headers, challengeHeader, false); future.getAndSetAuth(false); } else { // probably receiving Type2Msg, so we issue Type3Msg addType3NTLMAuthorizationHeader(wwwAuth, headers, realm, false); } return new Realm.RealmBuilder().clone(realm)// .setUri(uri)// .setMethodName(request.getMethod())// .build(); }
private Realm ntlmProxyChallenge(String wwwAuth, Request request, ProxyServer proxyServer, FluentCaseInsensitiveStringsMap headers, NettyResponseFuture<?> future) throws NTLMEngineException { future.getAndSetAuth(false); headers.remove(HttpHeaders.Names.PROXY_AUTHORIZATION); Realm realm = proxyServer.realmBuilder()// .setScheme(AuthScheme.NTLM)// .setUri(request.getUri())// .setMethodName(request.getMethod()).build(); addType3NTLMAuthorizationHeader(wwwAuth, headers, realm, true); return realm; }
private static Realm ntlmChallenge(final Connection c, final String wwwAuth, final Request request, final Realm realm, final boolean proxyInd) throws NTLMEngineException { final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); if (wwwAuth.equals("NTLM")) { // server replied bare NTLM => we didn't preemptively sent Type1Msg String challengeHeader = NTLMEngine.INSTANCE.generateType1Msg(); addNTLMAuthorizationHeader(headers, challengeHeader, proxyInd); } else { // probably receiving Type2Msg, so we issue Type3Msg addType3NTLMAuthorizationHeader(wwwAuth, headers, realm, proxyInd); // we mark NTLM as established for the Connection to // avoid preemptive NTLM Utils.setNtlmEstablished(c); } return new Realm.RealmBuilder().clone(realm)// .setUri(request.getUri())// .setMethodName(request.getMethod())// .build(); }
port = getPort(scheme, proxy.getPort()); } else { final Uri uri = request.getUri(); scheme = uri.getScheme(); host = uri.getHost();
private static Realm ntlmProxyChallenge(final Connection c, final String wwwAuth, final Request request, final ProxyServer proxyServer) throws NTLMEngineException { final FluentCaseInsensitiveStringsMap headers = request.getHeaders(); headers.remove(Header.ProxyAuthorization.toString()); Realm realm = proxyServer.realmBuilder()// .setScheme(AuthScheme.NTLM)// .setUri(request.getUri())// .setMethodName(request.getMethod()).build(); addType3NTLMAuthorizationHeader(wwwAuth, headers, realm, true); // we mark NTLM as established for the Connection to // avoid preemptive NTLM Utils.setNtlmEstablished(c); return realm; }
ClientBootstrap bootstrap = channelManager.getBootstrap(request.getUri().getScheme(), useProxy, useSSl);
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirects = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyEncoding(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }
private boolean exitAfterHandlingConnect(// final Channel channel,// final NettyResponseFuture<?> future,// final Request request,// ProxyServer proxyServer,// int statusCode,// HttpRequest httpRequest) throws IOException { if (statusCode == OK.getCode() && httpRequest.getMethod() == HttpMethod.CONNECT) { if (future.isKeepAlive()) future.attachChannel(channel, true); try { Uri requestUri = request.getUri(); String scheme = requestUri.getScheme(); String host = requestUri.getHost(); int port = getDefaultPort(requestUri); logger.debug("Connecting to proxy {} for scheme {}", proxyServer, scheme); channelManager.upgradeProtocol(channel.getPipeline(), scheme, host, port); } catch (Throwable ex) { requestSender.abort(channel, future, ex); } future.setReuseChannel(true); future.setConnectAllowed(false); requestSender.sendNextRequest(new RequestBuilder(future.getRequest()).build(), future); return true; } return false; }
private Realm kerberosProxyChallenge(Channel channel,// List<String> proxyAuth,// Request request,// ProxyServer proxyServer,// FluentCaseInsensitiveStringsMap headers,// NettyResponseFuture<?> future) throws NTLMEngineException { Uri uri = request.getUri(); try { String challengeHeader = SpnegoEngine.INSTANCE.generateToken(proxyServer.getHost()); headers.remove(HttpHeaders.Names.AUTHORIZATION); headers.add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); return proxyServer.realmBuilder()// .setUri(uri)// .setMethodName(request.getMethod())// .setScheme(Realm.AuthScheme.KERBEROS)// .build(); } catch (Throwable throwable) { String ntlmAuthenticate = getNTLM(proxyAuth); if (ntlmAuthenticate != null) { return ntlmProxyChallenge(ntlmAuthenticate, request, proxyServer, headers, future); } requestSender.abort(channel, future, throwable); return null; } }
? req.getUri() : httpTransactionContext.lastRedirectUri;
private Realm kerberosChallenge(Channel channel,// List<String> authHeaders,// Request request,// FluentCaseInsensitiveStringsMap headers,// Realm realm,// NettyResponseFuture<?> future) throws NTLMEngineException { Uri uri = request.getUri(); String host = request.getVirtualHost() == null ? uri.getHost() : request.getVirtualHost(); try { String challengeHeader = SpnegoEngine.INSTANCE.generateToken(host); headers.remove(HttpHeaders.Names.AUTHORIZATION); headers.add(HttpHeaders.Names.AUTHORIZATION, "Negotiate " + challengeHeader); return new Realm.RealmBuilder().clone(realm)// .setUri(uri)// .setMethodName(request.getMethod())// .setScheme(Realm.AuthScheme.KERBEROS)// .build(); } catch (Throwable throwable) { String ntlmAuthenticate = getNTLM(authHeaders); if (ntlmAuthenticate != null) { return ntlmChallenge(ntlmAuthenticate, request, headers, realm, future); } requestSender.abort(channel, future, throwable); return null; } }