hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1301572 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/impl/client/CompressionDecorator.java test/java/org/apache/http/impl/client/TestCompressionDecorator.java
Date Fri, 16 Mar 2012 15:01:27 GMT
Author: jonm
Date: Fri Mar 16 15:01:27 2012
New Revision: 1301572

URL: http://svn.apache.org/viewvc?rev=1301572&view=rev
Log:
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.

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CompressionDecorator.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCompressionDecorator.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CompressionDecorator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CompressionDecorator.java?rev=1301572&r1=1301571&r2=1301572&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CompressionDecorator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/client/CompressionDecorator.java
Fri Mar 16 15:01:27 2012
@@ -128,6 +128,7 @@ public class CompressionDecorator implem
             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) {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCompressionDecorator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCompressionDecorator.java?rev=1301572&r1=1301571&r2=1301572&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCompressionDecorator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/client/TestCompressionDecorator.java
Fri Mar 16 15:01:27 2012
@@ -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");



Mime
View raw message