HTTPCLIENT-1164: If we uncompress an entity on-the-fly, we should
also remove its Content-MD5 header, as it will likely no longer be accurate, and an upstream consumer may incorrectly reject the response on that basis. This way the decorator preserves semantic transparency. git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1301572 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
54c7e992fb
commit
3f99045e4f
|
@ -128,6 +128,7 @@ public class CompressionDecorator implements HttpClient {
|
|||
if (Boolean.TRUE.equals(context.getAttribute(ResponseContentEncoding.UNCOMPRESSED))) {
|
||||
response.removeHeaders("Content-Length");
|
||||
response.removeHeaders("Content-Encoding");
|
||||
response.removeHeaders("Content-MD5");
|
||||
}
|
||||
return response;
|
||||
} catch (HttpException e) {
|
||||
|
|
|
@ -270,7 +270,7 @@ public class TestCompressionDecorator {
|
|||
assertSame(handled, impl.execute(host, request, mockHandler, ctx));
|
||||
verify(mockResponse, never()).setEntity(any(HttpEntity.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void successfullyUncompressesContent() throws Exception {
|
||||
final String plainText = "hello\n";
|
||||
|
@ -311,6 +311,29 @@ public class TestCompressionDecorator {
|
|||
assertNull(result.getFirstHeader("Content-Encoding"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uncompressedResponseHasContentMD5Removed() throws Exception {
|
||||
final String plainText = "hello\n";
|
||||
HttpResponse response = getGzippedResponse(plainText);
|
||||
response.setHeader("Content-MD5","a checksum");
|
||||
backend.setResponse(response);
|
||||
|
||||
HttpResponse result = impl.execute(request);
|
||||
assertNull(result.getFirstHeader("Content-MD5"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unencodedResponseRetainsContentMD5() throws Exception {
|
||||
final String plainText = "hello\n";
|
||||
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
response.setHeader("Content-MD5","a checksum");
|
||||
response.setEntity(new ByteArrayEntity(plainText.getBytes()));
|
||||
backend.setResponse(response);
|
||||
|
||||
HttpResponse result = impl.execute(request);
|
||||
assertNotNull(result.getFirstHeader("Content-MD5"));
|
||||
}
|
||||
|
||||
private HttpResponse getGzippedResponse(final String plainText)
|
||||
throws IOException {
|
||||
HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
|
||||
|
|
Loading…
Reference in New Issue