public Object getPartitionKey() { return connectionPoolPartitioning.getPartitionKey(targetRequest.getUri(), targetRequest.getVirtualHost(), proxyServer); }
private Channel pollPooledChannel(Request request, ProxyServer proxy, AsyncHandler<?> asyncHandler) { try { asyncHandler.onConnectionPoolAttempt(); } catch (Exception e) { LOGGER.error("onConnectionPoolAttempt crashed", e); } Uri uri = request.getUri(); String virtualHost = request.getVirtualHost(); final Channel channel = channelManager.poll(uri, virtualHost, proxy, request.getChannelPoolPartitioning()); if (channel != null) { LOGGER.debug("Using pooled Channel '{}' for '{}' to '{}'", channel, request.getMethod(), uri); } return channel; }
if (proxyServer != null) host = proxyServer.getHost(); else if (request.getVirtualHost() != null) host = request.getVirtualHost(); else host = request.getUri().getHost();
private void kerberosChallenge(Realm realm, Request request, HttpHeaders headers) throws SpnegoEngineException { Uri uri = request.getUri(); String host = withDefault(request.getVirtualHost(), uri.getHost()); String challengeHeader = SpnegoEngine.instance(realm.getPrincipal(), realm.getPassword(), realm.getServicePrincipalName(), realm.getRealmName(), realm.isUseCanonicalHostname(), realm.getCustomLoginConfig(), realm.getLoginContextName()).generateToken(host); headers.set(AUTHORIZATION, NEGOTIATE + " " + challengeHeader); } }
String virtualHost = request.getVirtualHost(); headers.set(HOST, virtualHost != null ? virtualHost : hostHeader(uri));
SslHandler sslHandler; try { sslHandler = channelManager.addSslHandler(channel.pipeline(), uri, request.getVirtualHost(), proxyServer != null); } catch (Exception sslError) { onFailure(channel, sslError);
this.bodyParts = new ArrayList<>(prototype.getBodyParts()); this.virtualHost = prototype.getVirtualHost(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm();
requestBuilder.setVirtualHost(request.getVirtualHost());
public Object getPartitionKey() { return connectionPoolPartitioning.getPartitionKey(request.getUri(), request.getVirtualHost(), proxyServer); }
public Object getPartitionKey() { return connectionPoolPartitioning.getPartitionKey(request.getUri(), request.getVirtualHost(), proxyServer); }
private Channel pollAndVerifyCachedChannel(Request request, ProxyServer proxy, AsyncHandler<?> asyncHandler) { if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPool(); Uri uri = request.getUri(); String virtualHost = request.getVirtualHost(); final Channel channel = channelManager.poll(uri, virtualHost, proxy, request.getConnectionPoolPartitioning()); if (channel != null) { LOGGER.debug("Using cached Channel {}\n for uri {}\n", channel, uri); try { channelManager.verifyChannelPipeline(channel.pipeline(), uri, virtualHost); } catch (Exception ex) { LOGGER.debug(ex.getMessage(), ex); } } return channel; }
public static String hostHeader(Request request, Uri uri) { String virtualHost = request.getVirtualHost(); if (virtualHost != null) return virtualHost; else { String host = uri.getHost(); int port = uri.getPort(); return port == -1 || port == uri.getSchemeDefaultPort() ? host : host + ":" + port; } } }
public Channel pollAndVerifyCachedChannel(Request request, ProxyServer proxy, AsyncHandler<?> asyncHandler) { if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionPool(); Uri uri = request.getUri(); String virtualHost = request.getVirtualHost(); final Channel channel = channelManager.poll(uri, virtualHost, proxy, request.getConnectionPoolPartitioning()); if (channel != null) { LOGGER.debug("Using cached Channel {}\n for uri {}\n", channel, uri); try { // Always make sure the channel who got cached support the // proper protocol. It could // only occurs when a HttpMethod.CONNECT is used against a proxy // that requires upgrading from http to // https. channelManager.verifyChannelPipeline(channel.getPipeline(), uri, virtualHost); } catch (Exception ex) { LOGGER.debug(ex.getMessage(), ex); } } return channel; }
public static String perConnectionAuthorizationHeader(Request request, ProxyServer proxyServer, Realm realm) { String authorizationHeader = null; if (realm != null && realm.getUsePreemptiveAuth()) { switch (realm.getScheme()) { case NTLM: String msg = NtlmEngine.INSTANCE.generateType1Msg(); authorizationHeader = "NTLM " + msg; break; case KERBEROS: case SPNEGO: String host; if (proxyServer != null) host = proxyServer.getHost(); else if (request.getVirtualHost() != null) host = request.getVirtualHost(); else host = request.getUri().getHost(); authorizationHeader = "Negotiate " + SpnegoEngine.instance().generateToken(host); break; default: break; } } return authorizationHeader; }
private void onFutureSuccess(final Channel channel) throws Exception { Request request = future.getRequest(); Uri uri = request.getUri(); // in case of proxy tunneling, we'll add the SslHandler later, after the CONNECT request if (future.getProxyServer() == null && uri.isSecured()) { SslHandler sslHandler = channelManager.addSslHandler(channel.pipeline(), uri, request.getVirtualHost()); sslHandler.handshakeFuture().addListener(new GenericFutureListener<Future<Channel>>() { @Override public void operationComplete(Future<Channel> handshakeFuture) throws Exception { if (handshakeFuture.isSuccess()) { final AsyncHandler<T> asyncHandler = future.getAsyncHandler(); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted(); writeRequest(channel); } else { onFutureFailure(channel, handshakeFuture.cause()); } } }); } else { writeRequest(channel); } }
private Realm kerberosChallenge(Channel channel,// List<String> authHeaders,// Request request,// FluentCaseInsensitiveStringsMap headers,// Realm realm,// NettyResponseFuture<?> future) { 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 (SpnegoEngineException throwable) { String ntlmAuthenticate = getNTLM(authHeaders); if (ntlmAuthenticate != null) { return ntlmChallenge(ntlmAuthenticate, request, headers, realm, future); } requestSender.abort(channel, future, throwable); return null; } }
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; } }
private Realm kerberosChallenge(Channel channel,// List<String> authHeaders,// Request request,// FluentCaseInsensitiveStringsMap headers,// Realm realm,// NettyResponseFuture<?> future) { 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 (SpnegoEngineException throwable) { String ntlmAuthenticate = getNTLM(authHeaders); if (ntlmAuthenticate != null) { return ntlmChallenge(ntlmAuthenticate, request, headers, realm, future); } requestSender.abort(channel, future, throwable); return null; } }
private void onFutureSuccess(final Channel channel) throws Exception { Request request = future.getRequest(); Uri uri = request.getUri(); // in case of proxy tunneling, we'll add the SslHandler later, after the CONNECT request if (future.getProxyServer() == null && uri.isSecured()) { SslHandler sslHandler = channelManager.addSslHandler(channel.getPipeline(), uri, request.getVirtualHost()); sslHandler.handshake().addListener(new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture handshakeFuture) throws Exception { if (handshakeFuture.isSuccess()) { final AsyncHandler<T> asyncHandler = future.getAsyncHandler(); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onSslHandshakeCompleted(); writeRequest(channel); } else { onFutureFailure(channel, handshakeFuture.getCause()); } } }); } else { writeRequest(channel); } }
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.byteBufferData = prototype.getByteBufferData(); 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.followRedirect = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyCharset(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }