diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestClientConnControl.java b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestClientConnControl.java index 902cac274..5e01c821f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestClientConnControl.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/protocol/RequestClientConnControl.java @@ -44,9 +44,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * This protocol interceptor is responsible for adding {@code Connection} - * or {@code Proxy-Connection} headers to the outgoing requests, which - * is essential for managing persistence of {@code HTTP/1.0} connections. + * This protocol interceptor is responsible for adding the {@code Connection} + * header to the outgoing requests, which is essential for managing persistence + * of {@code HTTP/1.0} connections. * * @since 4.0 */ @@ -55,8 +55,6 @@ public class RequestClientConnControl implements HttpRequestInterceptor { private final Logger log = LoggerFactory.getLogger(getClass()); - private static final String PROXY_CONN_DIRECTIVE = "Proxy-Connection"; - public RequestClientConnControl() { super(); } @@ -68,7 +66,6 @@ public class RequestClientConnControl implements HttpRequestInterceptor { final String method = request.getMethod(); if (method.equalsIgnoreCase("CONNECT")) { - request.setHeader(PROXY_CONN_DIRECTIVE, HeaderElements.KEEP_ALIVE); return; } @@ -86,11 +83,6 @@ public class RequestClientConnControl implements HttpRequestInterceptor { request.addHeader(HttpHeaders.CONNECTION, HeaderElements.KEEP_ALIVE); } } - if (route.getHopCount() == 2 && !route.isTunnelled()) { - if (!request.containsHeader(PROXY_CONN_DIRECTIVE)) { - request.addHeader(PROXY_CONN_DIRECTIVE, HeaderElements.KEEP_ALIVE); - } - } } } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestClientConnControl.java b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestClientConnControl.java index b4ce09a8d..2c7f5df29 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestClientConnControl.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/protocol/TestRequestClientConnControl.java @@ -55,11 +55,8 @@ public class TestRequestClientConnControl { final HttpRequestInterceptor interceptor = new RequestClientConnControl(); interceptor.process(request, null, context); - final Header header1 = request.getFirstHeader("Proxy-Connection"); - Assert.assertNotNull(header1); - Assert.assertEquals(HeaderElements.KEEP_ALIVE, header1.getValue()); - final Header header2 = request.getFirstHeader(HttpHeaders.CONNECTION); - Assert.assertNull(header2); + final Header header = request.getFirstHeader(HttpHeaders.CONNECTION); + Assert.assertNull(header); } @Test @@ -75,11 +72,9 @@ public class TestRequestClientConnControl { final HttpRequestInterceptor interceptor = new RequestClientConnControl(); interceptor.process(request, null, context); - final Header header1 = request.getFirstHeader(HttpHeaders.CONNECTION); - Assert.assertNotNull(header1); - Assert.assertEquals(HeaderElements.KEEP_ALIVE, header1.getValue()); - final Header header2 = request.getFirstHeader("Proxy-Connection"); - Assert.assertNull(header2); + final Header header = request.getFirstHeader(HttpHeaders.CONNECTION); + Assert.assertNotNull(header); + Assert.assertEquals(HeaderElements.KEEP_ALIVE, header.getValue()); } @Test @@ -97,11 +92,9 @@ public class TestRequestClientConnControl { final HttpRequestInterceptor interceptor = new RequestClientConnControl(); interceptor.process(request, null, context); - final Header header1 = request.getFirstHeader(HttpHeaders.CONNECTION); - Assert.assertNotNull(header1); - Assert.assertEquals(HeaderElements.KEEP_ALIVE, header1.getValue()); - final Header header2 = request.getFirstHeader("Proxy-Connection"); - Assert.assertNull(header2); + final Header header = request.getFirstHeader(HttpHeaders.CONNECTION); + Assert.assertNotNull(header); + Assert.assertEquals(HeaderElements.KEEP_ALIVE, header.getValue()); } @Test @@ -119,11 +112,8 @@ public class TestRequestClientConnControl { final HttpRequestInterceptor interceptor = new RequestClientConnControl(); interceptor.process(request, null, context); - final Header header1 = request.getFirstHeader("Proxy-Connection"); - Assert.assertNotNull(header1); - Assert.assertEquals(HeaderElements.KEEP_ALIVE, header1.getValue()); - final Header header2 = request.getFirstHeader(HttpHeaders.CONNECTION); - Assert.assertNull(header2); + final Header header = request.getFirstHeader(HttpHeaders.CONNECTION); + Assert.assertNull(header); } @Test @@ -142,32 +132,9 @@ public class TestRequestClientConnControl { final HttpRequestInterceptor interceptor = new RequestClientConnControl(); interceptor.process(request, null, context); - final Header header1 = request.getFirstHeader(HttpHeaders.CONNECTION); - Assert.assertNotNull(header1); - Assert.assertEquals(HeaderElements.CLOSE, header1.getValue()); - final Header header2 = request.getFirstHeader("Proxy-Connection"); - Assert.assertNull(header2); - } - - @Test - public void testPreserveCustomProxyConnectionHeader() throws Exception { - final HttpRequest request = new BasicHttpRequest("GET", "/"); - request.addHeader("Proxy-Connection", HeaderElements.CLOSE); - final HttpClientContext context = HttpClientContext.create(); - - final HttpHost target = new HttpHost("http", "localhost", 80); - final HttpHost proxy = new HttpHost("localhost", 8080); - final HttpRoute route = new HttpRoute(target, null, proxy, false, - TunnelType.PLAIN, LayerType.PLAIN); - - context.setAttribute(HttpClientContext.HTTP_ROUTE, route); - - final HttpRequestInterceptor interceptor = new RequestClientConnControl(); - interceptor.process(request, null, context); - - final Header header1 = request.getFirstHeader("Proxy-Connection"); - Assert.assertNotNull(header1); - Assert.assertEquals(HeaderElements.CLOSE, header1.getValue()); + final Header header = request.getFirstHeader(HttpHeaders.CONNECTION); + Assert.assertNotNull(header); + Assert.assertEquals(HeaderElements.CLOSE, header.getValue()); } }