@Override protected void onSuccess(List<InetSocketAddress> addresses) { NettyConnectListener<T> connectListener = new NettyConnectListener<>(future, NettyRequestSender.this, channelManager, connectionSemaphore); NettyChannelConnector connector = new NettyChannelConnector(request.getLocalAddress(), addresses, asyncHandler, clientState); if (!future.isDone()) { // Do not throw an exception when we need an extra connection for a redirect // FIXME why? This violate the max connection per host handling, right? channelManager.getBootstrap(request.getUri(), request.getNameResolver(), proxy) .addListener((Future<Bootstrap> whenBootstrap) -> { if (whenBootstrap.isSuccess()) { connector.connect(whenBootstrap.get(), connectListener); } else { abort(null, future, whenBootstrap.cause()); } }); } }
this.uri = prototype.getUri(); this.address = prototype.getAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new DefaultHttpHeaders(validateHeaders); this.headers.add(prototype.getHeaders());
.setChannelPoolPartitioning(request.getChannelPoolPartitioning()) .setFollowRedirect(true) .setLocalAddress(request.getLocalAddress()) .setNameResolver(request.getNameResolver()) .setProxyServer(request.getProxyServer())
private ChannelFuture connect(Request request, Uri uri, ProxyServer proxy, boolean useProxy, Bootstrap bootstrap, AsyncHandler<?> asyncHandler) throws UnknownHostException { InetSocketAddress remoteAddress = remoteAddress(request, uri, proxy, useProxy); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onDnsResolved(remoteAddress.getAddress()); if (request.getLocalAddress() != null) return bootstrap.connect(remoteAddress, new InetSocketAddress(request.getLocalAddress(), 0)); else return bootstrap.connect(remoteAddress); }
private ChannelFuture connect(Request request, Uri uri, ProxyServer proxy, boolean useProxy, ClientBootstrap bootstrap, AsyncHandler<?> asyncHandler) throws UnknownHostException { InetSocketAddress remoteAddress = remoteAddress(request, uri, proxy, useProxy); if (asyncHandler instanceof AsyncHandlerExtensions) AsyncHandlerExtensions.class.cast(asyncHandler).onDnsResolved(remoteAddress.getAddress()); if (request.getLocalAddress() != null) return bootstrap.connect(remoteAddress, new InetSocketAddress(request.getLocalAddress(), 0)); else return bootstrap.connect(remoteAddress); }
public ChannelConnector(Request request, ProxyServer proxy, boolean useProxy, AsyncHandler<?> asyncHandler) throws UnknownHostException { this.asyncHandlerExtensions = asyncHandler instanceof AsyncHandlerExtensions ? (AsyncHandlerExtensions) asyncHandler : null; NameResolution[] resolutions; Uri uri = request.getUri(); int port = uri.getExplicitPort(); if (request.getInetAddress() != null) { resolutions = new NameResolution[] { new NameResolution(request.getInetAddress()) }; } else if (!useProxy || ignoreProxy(proxy, uri.getHost())) { resolutions = request.getNameResolver().resolve(uri.getHost()); } else { resolutions = request.getNameResolver().resolve(proxy.getHost()); port = uri.isSecured() ? proxy.getSecuredPort(): proxy.getPort(); } if (asyncHandlerExtensions != null) asyncHandlerExtensions.onDnsResolved(resolutions); remoteAddresses = new InetSocketAddress[resolutions.length]; for (int i = 0; i < resolutions.length; i ++) { remoteAddresses[i] = new InetSocketAddress(resolutions[i].address, port); } if (request.getLocalAddress() != null) { localAddress = new InetSocketAddress(request.getLocalAddress(), 0); } else { localAddress = null; } }
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(); } }
.setLocalInetAddress(request.getLocalAddress())//
.setLocalInetAddress(request.getLocalAddress())//
.setLocalInetAddress(request.getLocalAddress())//
.setLocalInetAddress(request.getLocalAddress())//