Search in sources :

Example 1 with CONNECT

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

the class NettyRequestSender method sendRequestWithCertainForceConnect.

/**
 * 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, ProxyServer proxyServer, boolean performConnectRequest) {
    NettyResponseFuture<T> newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, performConnectRequest);
    Channel channel = getOpenChannel(future, request, proxyServer, asyncHandler);
    return Channels.isChannelActive(channel) ? sendRequestWithOpenChannel(newFuture, asyncHandler, channel) : 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)

Example 2 with CONNECT

use of org.asynchttpclient.util.HttpConstants.Methods.CONNECT 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)2 EXPECT (io.netty.handler.codec.http.HttpHeaderNames.EXPECT)2 CONNECT (org.asynchttpclient.util.HttpConstants.Methods.CONNECT)2 GET (org.asynchttpclient.util.HttpConstants.Methods.GET)2