Skip to content

Commit 02cbc5c

Browse files
committed
minor optim: only compute isConnectDone when necessary
1 parent c3879c8 commit 02cbc5c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,27 @@ public <T> ListenableFuture<T> sendRequest(final Request request,//
8989
validateWebSocketRequest(request, asyncHandler);
9090

9191
ProxyServer proxyServer = getProxyServer(config, request);
92-
boolean connectIsDone = future != null //
93-
&& future.getNettyRequest() != null //
94-
&& future.getNettyRequest().getHttpRequest().getMethod() == HttpMethod.CONNECT //
95-
&& !request.getMethod().equals(HttpMethod.CONNECT.name());
9692

9793
// websockets use connect tunnelling to work with proxies
98-
if (proxyServer != null && (request.getUri().isSecured() || request.getUri().isWebSocket()) && !connectIsDone)
99-
// SSL proxy or websocket, have to handle CONNECT
94+
if (proxyServer != null && (request.getUri().isSecured() || request.getUri().isWebSocket()) && !isConnectDone(request, future))
10095
if (future != null && future.isConnectAllowed())
101-
// CONNECT forced
96+
// SSL proxy or websocket: CONNECT for sure
10297
return sendRequestWithCertainForceConnect(request, asyncHandler, future, reclaimCache, proxyServer, true);
10398
else
99+
// CONNECT will depend if we can pool or connection or if we have to open a new one
104100
return sendRequestThroughSslProxy(request, asyncHandler, future, reclaimCache, proxyServer);
105101
else
102+
// no CONNECT for sure
106103
return sendRequestWithCertainForceConnect(request, asyncHandler, future, reclaimCache, proxyServer, false);
107104
}
108105

106+
private boolean isConnectDone(Request request,NettyResponseFuture<?> future) {
107+
return future != null //
108+
&& future.getNettyRequest() != null //
109+
&& future.getNettyRequest().getHttpRequest().getMethod() == HttpMethod.CONNECT //
110+
&& !request.getMethod().equals(HttpMethod.CONNECT.name());
111+
}
112+
109113
/**
110114
* We know for sure if we have to force to connect or not, so we can build
111115
* the HttpRequest right away This reduces the probability of having a
@@ -211,7 +215,7 @@ private <T> ListenableFuture<T> sendRequestWithOpenChannel(Request request, Prox
211215
future.setChannelState(ChannelState.POOLED);
212216
future.attachChannel(channel, false);
213217

214-
LOGGER.debug("Using cached Channel {} for {} '{}'", channel, future.getNettyRequest().getHttpRequest().getMethod(), future.getNettyRequest().getHttpRequest().getUri());
218+
LOGGER.debug("Using open Channel {} for {} '{}'", channel, future.getNettyRequest().getHttpRequest().getMethod(), future.getNettyRequest().getHttpRequest().getUri());
215219

216220
if (Channels.isChannelValid(channel)) {
217221
Channels.setAttribute(channel, future);
@@ -452,7 +456,7 @@ private Channel pollPooledChannel(Request request, ProxyServer proxy, AsyncHandl
452456
final Channel channel = channelManager.poll(uri, virtualHost, proxy, request.getConnectionPoolPartitioning());
453457

454458
if (channel != null) {
455-
LOGGER.debug("Using cached Channel {}\n for uri {}\n", channel, uri);
459+
LOGGER.debug("Using polled Channel {}\n for uri {}\n", channel, uri);
456460
}
457461
return channel;
458462
}

0 commit comments

Comments
 (0)