Skip to content

Commit 14667e0

Browse files
author
Stephane Landelle
committed
Set Connection header as close when connection pooling is disabled, partial fix for #254
Grizzly provider fails on GrizzlyBasicAuthTest.basicAuthFileNoKeepAliveTest
1 parent f3e5fbd commit 14667e0

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
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
@@ -491,7 +491,7 @@ private void configure(URI uri, HttpURLConnection urlConnection, Request request
491491
}
492492
}
493493

494-
String ka = config.getAllowPoolingConnection() ? "keep-alive" : "close";
494+
String ka = AsyncHttpProviderUtils.keepAliveHeaderValue(config);
495495
urlConnection.setRequestProperty("Connection", ka);
496496
ProxyServer proxyServer = ProxyUtils.getProxyServer(config, request);
497497
if (proxyServer != null) {

api/src/main/java/com/ning/http/util/AsyncHttpProviderUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,4 +599,8 @@ public static void checkBodyParts(int statusCode, Collection<HttpResponseBodyPar
599599
throw new IllegalStateException(BODY_NOT_COMPUTED);
600600
}
601601
}
602+
603+
public static String keepAliveHeaderValue(AsyncHttpClientConfig config) {
604+
return config.getAllowPoolingConnection() ? "keep-alive" : "close";
605+
}
602606
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,12 @@ else if (uri.getRawQuery() != null)
705705
}
706706

707707
if (!webSocket && !request.getHeaders().containsKey(HttpHeaders.Names.CONNECTION)) {
708-
nettyRequest.setHeader(HttpHeaders.Names.CONNECTION, "keep-alive");
708+
nettyRequest.setHeader(HttpHeaders.Names.CONNECTION, AsyncHttpProviderUtils.keepAliveHeaderValue(config));
709709
}
710710

711711
if (proxyServer != null) {
712712
if (!request.getHeaders().containsKey("Proxy-Connection")) {
713-
nettyRequest.setHeader("Proxy-Connection", "keep-alive");
713+
nettyRequest.setHeader("Proxy-Connection", AsyncHttpProviderUtils.keepAliveHeaderValue(config));
714714
}
715715

716716
if (proxyServer.getPrincipal() != null) {

providers/netty/src/test/java/com/ning/http/client/providers/netty/NettyBasicAuthTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.ning.http.client.AsyncHttpClientConfig;
2222
import com.ning.http.client.async.BasicAuthTest;
2323

24+
@Test
2425
public class NettyBasicAuthTest extends BasicAuthTest {
2526

2627
@Override

0 commit comments

Comments
 (0)