HTTPCLIENT-1162: do not override 'Accept-Encoding' header if already present

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1242782 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2012-02-10 14:14:30 +00:00
parent 747593abb7
commit d969fe8774
2 changed files with 16 additions and 1 deletions

View File

@ -52,7 +52,9 @@ public class RequestAcceptEncoding implements HttpRequestInterceptor {
final HttpContext context) throws HttpException, IOException {
/* Signal support for Accept-Encoding transfer encodings. */
request.addHeader("Accept-Encoding", "gzip,deflate");
if (!request.containsHeader("Accept-Encoding")) {
request.addHeader("Accept-Encoding", "gzip,deflate");
}
}
}

View File

@ -50,4 +50,17 @@ public class TestRequestAcceptEncoding {
Assert.assertEquals("gzip,deflate", header.getValue());
}
@Test
public void testAcceptEncodingAlreadyPResent() throws Exception {
HttpRequest request = new BasicHttpRequest("GET", "/");
request.addHeader("Accept-Encoding", "stuff");
HttpContext context = new BasicHttpContext();
HttpRequestInterceptor interceptor = new RequestAcceptEncoding();
interceptor.process(request, context);
Header header = request.getFirstHeader("Accept-Encoding");
Assert.assertNotNull(header);
Assert.assertEquals("stuff", header.getValue());
}
}