Skip to content

Commit 5847094

Browse files
committed
nit
* rename forceConnect into performConnectRequest * drop performingNextRequest that was no longer used
1 parent f8e8232 commit 5847094

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

Diff for: client/src/main/java/org/asynchttpclient/netty/request/NettyRequestFactory.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public void setProxyAuthorizationHeader(HttpHeaders headers, String proxyAuthori
123123
headers.set(PROXY_AUTHORIZATION, proxyAuthorizationHeader);
124124
}
125125

126-
public NettyRequest newNettyRequest(Request request, boolean forceConnect, ProxyServer proxyServer, Realm realm, Realm proxyRealm) {
126+
public NettyRequest newNettyRequest(Request request, boolean performConnectRequest, ProxyServer proxyServer, Realm realm, Realm proxyRealm) {
127127

128128
Uri uri = request.getUri();
129-
HttpMethod method = forceConnect ? HttpMethod.CONNECT : HttpMethod.valueOf(request.getMethod());
129+
HttpMethod method = performConnectRequest ? HttpMethod.CONNECT : HttpMethod.valueOf(request.getMethod());
130130
boolean connect = method == HttpMethod.CONNECT;
131131

132132
HttpVersion httpVersion = HttpVersion.HTTP_1_1;

Diff for: client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java

+26-27
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,15 @@ public <T> ListenableFuture<T> sendRequest(final Request request, //
113113
// Proxy with HTTPS or WebSocket: CONNECT for sure
114114
if (future != null && future.isConnectAllowed()) {
115115
// Perform CONNECT
116-
return sendRequestWithCertainForceConnect(request, asyncHandler, future, performingNextRequest,
117-
proxyServer, true);
116+
return sendRequestWithCertainForceConnect(request, asyncHandler, future, proxyServer, true);
118117
} else {
119118
// CONNECT will depend if we can pool or connection or if we have to open a new
120119
// one
121-
return sendRequestThroughSslProxy(request, asyncHandler, future, performingNextRequest, proxyServer);
120+
return sendRequestThroughSslProxy(request, asyncHandler, future, proxyServer);
122121
}
123122
} else {
124123
// no CONNECT for sure
125-
return sendRequestWithCertainForceConnect(request, asyncHandler, future, performingNextRequest, proxyServer,
126-
false);
124+
return sendRequestWithCertainForceConnect(request, asyncHandler, future, proxyServer, false);
127125
}
128126
}
129127

@@ -143,57 +141,58 @@ private <T> ListenableFuture<T> sendRequestWithCertainForceConnect(//
143141
Request request, //
144142
AsyncHandler<T> asyncHandler, //
145143
NettyResponseFuture<T> future, //
146-
boolean performingNextRequest, //
147144
ProxyServer proxyServer, //
148-
boolean forceConnect) {
145+
boolean performConnectRequest) {
149146

150147
NettyResponseFuture<T> newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer,
151-
forceConnect);
148+
performConnectRequest);
152149

153150
Channel channel = getOpenChannel(future, request, proxyServer, asyncHandler);
154151

155-
if (Channels.isChannelActive(channel))
156-
return sendRequestWithOpenChannel(request, proxyServer, newFuture, asyncHandler, channel);
157-
else
158-
return sendRequestWithNewChannel(request, proxyServer, newFuture, asyncHandler, performingNextRequest);
152+
return Channels.isChannelActive(channel)
153+
? sendRequestWithOpenChannel(request, proxyServer, newFuture, asyncHandler, channel)
154+
: sendRequestWithNewChannel(request, proxyServer, newFuture, asyncHandler);
159155
}
160156

161157
/**
162158
* Using CONNECT depends on wither we can fetch a valid channel or not Loop
163159
* until we get a valid channel from the pool and it's still valid once the
164160
* request is built @
165161
*/
166-
@SuppressWarnings("unused")
167162
private <T> ListenableFuture<T> sendRequestThroughSslProxy(//
168163
Request request, //
169164
AsyncHandler<T> asyncHandler, //
170165
NettyResponseFuture<T> future, //
171-
boolean performingNextRequest, //
172166
ProxyServer proxyServer) {
173167

174168
NettyResponseFuture<T> newFuture = null;
175169
for (int i = 0; i < 3; i++) {
176170
Channel channel = getOpenChannel(future, request, proxyServer, asyncHandler);
177-
if (Channels.isChannelActive(channel))
178-
if (newFuture == null)
179-
newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, false);
180171

181-
if (Channels.isChannelActive(channel))
182-
// if the channel is still active, we can use it, otherwise try
183-
// gain
184-
return sendRequestWithOpenChannel(request, proxyServer, newFuture, asyncHandler, channel);
185-
else
172+
if (channel == null) {
186173
// pool is empty
187174
break;
175+
}
176+
177+
if (newFuture == null) {
178+
newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, false);
179+
}
180+
181+
if (Channels.isChannelActive(channel)) {
182+
// if the channel is still active, we can use it,
183+
// otherwise, channel was closed by the time we computed the request, try again
184+
return sendRequestWithOpenChannel(request, proxyServer, newFuture, asyncHandler, channel);
185+
}
188186
}
189187

188+
// couldn't poll an active channel
190189
newFuture = newNettyRequestAndResponseFuture(request, asyncHandler, future, proxyServer, true);
191-
return sendRequestWithNewChannel(request, proxyServer, newFuture, asyncHandler, performingNextRequest);
190+
return sendRequestWithNewChannel(request, proxyServer, newFuture, asyncHandler);
192191
}
193192

194193
private <T> NettyResponseFuture<T> newNettyRequestAndResponseFuture(final Request request,
195194
final AsyncHandler<T> asyncHandler, NettyResponseFuture<T> originalFuture, ProxyServer proxy,
196-
boolean forceConnect) {
195+
boolean performConnectRequest) {
197196

198197
Realm realm = null;
199198
if (originalFuture != null) {
@@ -212,7 +211,8 @@ private <T> NettyResponseFuture<T> newNettyRequestAndResponseFuture(final Reques
212211
proxyRealm = proxy.getRealm();
213212
}
214213

215-
NettyRequest nettyRequest = requestFactory.newNettyRequest(request, forceConnect, proxy, realm, proxyRealm);
214+
NettyRequest nettyRequest = requestFactory.newNettyRequest(request, performConnectRequest, proxy, realm,
215+
proxyRealm);
216216

217217
if (originalFuture == null) {
218218
NettyResponseFuture<T> future = newNettyResponseFuture(request, asyncHandler, nettyRequest, proxy);
@@ -284,8 +284,7 @@ private <T> ListenableFuture<T> sendRequestWithNewChannel(//
284284
Request request, //
285285
ProxyServer proxy, //
286286
NettyResponseFuture<T> future, //
287-
AsyncHandler<T> asyncHandler, //
288-
boolean performingNextRequest) {
287+
AsyncHandler<T> asyncHandler) {
289288

290289
// some headers are only set when performing the first request
291290
HttpHeaders headers = future.getNettyRequest().getHttpRequest().headers();

0 commit comments

Comments
 (0)