Skip to content

Commit 719fbe8

Browse files
author
Stephane Landelle
committed
Merge pull request #252 from suenway/master
Patch for inappropriate connection channel when working at proxy mode
2 parents f7a6c68 + 6deae2e commit 719fbe8

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

api/src/main/java/com/ning/http/client/providers/jdk/JDKAsyncHttpProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private HttpURLConnection createUrlConnection(Request request) throws IOExceptio
179179
urlConnection =
180180
(HttpURLConnection) AsyncHttpProviderUtils.createUri(request.getUrl()).toURL().openConnection(Proxy.NO_PROXY);
181181
} else {
182-
urlConnection = (HttpURLConnection) AsyncHttpProviderUtils.createUri(request.getUrl()).toURL().openConnection(proxy);
182+
urlConnection = (HttpURLConnection) AsyncHttpProviderUtils.createUri(proxyServer.toString()).toURL().openConnection(proxy);
183183
}
184184

185185
if (request.getUrl().startsWith("https")) {

providers/grizzly/src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,8 @@ public void updated(Connection result) {
25492549

25502550
private static String getPoolKey(final Request request) {
25512551
final ConnectionPoolKeyStrategy keyStrategy = request.getConnectionPoolKeyStrategy();
2552-
return keyStrategy.getKey(request.getURI());
2552+
String savedUrlInConnPool = request.getProxyServer() != null ? request.getProxyServer().toString() : request.getUrl();
2553+
return keyStrategy.getKey(AsyncHttpProviderUtils.createUri(AsyncHttpProviderUtils.getBaseUrl(savedUrlInConnPool)));
25532554
}
25542555

25552556
// ------------------------------------------------------ Nested Classes

providers/netty/src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProvider.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,8 @@ private Realm ntlmProxyChallenge(List<String> wwwAuth,
12791279
private void drainChannel(final ChannelHandlerContext ctx, final NettyResponseFuture<?> future, final boolean keepAlive, final URI uri) {
12801280
ctx.setAttachment(new AsyncCallable(future) {
12811281
public Object call() throws Exception {
1282-
if (keepAlive && ctx.getChannel().isReadable() && connectionsPool.offer(future.getConnectionPoolKeyStrategy().getKey(uri), ctx.getChannel())) {
1282+
URI connUrl = future.getRequest().getProxyServer() == null ? future.getURI() : AsyncHttpProviderUtils.createUri(future.getRequest().getProxyServer().toString());
1283+
if (keepAlive && ctx.getChannel().isReadable() && connectionsPool.offer(future.getConnectionPoolKeyStrategy().getKey(connUrl), ctx.getChannel())) {
12831284
return null;
12841285
}
12851286

@@ -1476,7 +1477,7 @@ private void finishUpdate(final NettyResponseFuture<?> future, final ChannelHand
14761477
drainChannel(ctx, future, future.getKeepAlive(), future.getURI());
14771478
} else {
14781479
if (future.getKeepAlive() && ctx.getChannel().isReadable() &&
1479-
connectionsPool.offer(future.getConnectionPoolKeyStrategy().getKey(future.getURI()), ctx.getChannel())) {
1480+
(connectionsPool.offer(AsyncHttpProviderUtils.getBaseUrl(future.getRequest().getProxyServer() == null ? future.getURI() : AsyncHttpProviderUtils.createUri(future.getRequest().getProxyServer().toString())), ctx.getChannel()))){
14801481
markAsDone(future, ctx);
14811482
return;
14821483
}

0 commit comments

Comments
 (0)