private static String getPoolKey(Request request, ProxyServer proxyServer) { return request.getConnectionPoolKeyStrategy().getKey(request.getURI(), proxyServer); }
private <T> NettyResponseFuture<T> newNettyResponseFuture(UriComponents uri, Request request, AsyncHandler<T> asyncHandler, NettyRequest nettyRequest, ProxyServer proxyServer) { NettyResponseFuture<T> future = new NettyResponseFuture<T>(// uri,// request,// asyncHandler,// nettyRequest,// config.getMaxRequestRetry(),// request.getConnectionPoolKeyStrategy(),// proxyServer); String expectHeader = request.getHeaders().getFirstValue(HttpHeaders.Names.EXPECT); if (expectHeader != null && expectHeader.equalsIgnoreCase(HttpHeaders.Values.CONTINUE)) future.setDontWriteBodyBecauseExpectContinue(true); return future; }
/** * We know for sure if we have to force to connect or not, so we can * build the HttpRequest right away * This reduces the probability of having a pooled channel closed by the * server by the time we build the request */ private <T> ListenableFuture<T> sendRequestWithCertainForceConnect(// Request request,// AsyncHandler<T> asyncHandler,// NettyResponseFuture<T> future,// boolean reclaimCache,// UriComponents uri,// ProxyServer proxyServer,// boolean useProxy,// boolean forceConnect) throws IOException { NettyResponseFuture<T> newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, uri, proxyServer, forceConnect); Channel channel = getCachedChannel(future, uri, request.getConnectionPoolKeyStrategy(), proxyServer); if (Channels.isChannelValid(channel)) return sendRequestWithCachedChannel(request, uri, proxyServer, newFuture, asyncHandler, channel); else return sendRequestWithNewChannel(request, uri, proxyServer, useProxy, newFuture, asyncHandler, reclaimCache); }
/** * Using CONNECT depends on wither we can fetch a valid channel or not * Loop until we get a valid channel from the pool and it's still valid * once the request is built */ @SuppressWarnings("unused") private <T> ListenableFuture<T> sendRequestThroughSslProxy(// Request request,// AsyncHandler<T> asyncHandler,// NettyResponseFuture<T> future,// boolean reclaimCache,// UriComponents uri,// ProxyServer proxyServer) throws IOException { NettyResponseFuture<T> newFuture = null; for (int i = 0; i < 3; i++) { Channel channel = getCachedChannel(future, uri, request.getConnectionPoolKeyStrategy(), proxyServer); if (Channels.isChannelValid(channel)) if (newFuture == null) newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, uri, proxyServer, false); if (Channels.isChannelValid(channel)) // if the channel is still active, we can use it, otherwise try // gain return sendRequestWithCachedChannel(request, uri, proxyServer, newFuture, asyncHandler, channel); else // pool is empty break; } newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, uri, proxyServer, true); return sendRequestWithNewChannel(request, uri, proxyServer, true, newFuture, asyncHandler, reclaimCache); }
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<Cookie>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.stringData = prototype.getStringData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<Param>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<Part>(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.connectionPoolKeyStrategy = prototype.getConnectionPoolKeyStrategy(); } }