Search in sources :

Example 1 with GET

use of org.asynchttpclient.util.HttpConstants.Methods.GET in project async-http-client by AsyncHttpClient.

the class NettyRequestSender method sendRequestThroughProxy.

/**
 * 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 @
 */
private <T> ListenableFuture<T> sendRequestThroughProxy(Request request, AsyncHandler<T> asyncHandler, NettyResponseFuture<T> future, ProxyServer proxyServer) {
    NettyResponseFuture<T> newFuture = null;
    for (int i = 0; i < 3; i++) {
        Channel channel = getOpenChannel(future, request, proxyServer, asyncHandler);
        if (channel == null) {
            // pool is empty
            break;
        }
        if (newFuture == null) {
            newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, false);
        }
        if (Channels.isChannelActive(channel)) {
            // otherwise, channel was closed by the time we computed the request, try again
            return sendRequestWithOpenChannel(newFuture, asyncHandler, channel);
        }
    }
    // couldn't poll an active channel
    newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, true);
    return sendRequestWithNewChannel(request, proxyServer, newFuture, asyncHandler);
}
Also used : CONNECT(org.asynchttpclient.util.HttpConstants.Methods.CONNECT) GET(org.asynchttpclient.util.HttpConstants.Methods.GET) EXPECT(io.netty.handler.codec.http.HttpHeaderNames.EXPECT) Channel(io.netty.channel.Channel)

Aggregations

Channel (io.netty.channel.Channel)1 EXPECT (io.netty.handler.codec.http.HttpHeaderNames.EXPECT)1 CONNECT (org.asynchttpclient.util.HttpConstants.Methods.CONNECT)1 GET (org.asynchttpclient.util.HttpConstants.Methods.GET)1