[HTTPCLIENT-1957] Remove use of Proxy-Connection header
This closes #132
This commit is contained in:
parent
354ae3586e
commit
812f18b453
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue