hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1440671 - in /httpcomponents/httpclient/branches/4.2.x: ./ httpclient/src/main/java/org/apache/http/client/protocol/ httpclient/src/test/java/org/apache/http/client/protocol/
Date Wed, 30 Jan 2013 21:12:38 GMT
Author: olegk
Date: Wed Jan 30 21:12:38 2013
New Revision: 1440671

URL: http://svn.apache.org/viewvc?rev=1440671&view=rev
Log:
HTTPCLIENT-1312: Zero length content entities with a Content-Encoding header cause an I/O
error when an attempt is made to consume such entity

Modified:
    httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
    httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java

Modified: httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt?rev=1440671&r1=1440670&r2=1440671&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/branches/4.2.x/RELEASE_NOTES.txt Wed Jan 30 21:12:38 2013
@@ -1,6 +1,10 @@
 Changes since Release 4.2.3
 -------------------
 
+* [HTTPCLIENT-1312] Zero length content entities with a Content-Encoding header cause 
+  an I/O error when an attempt is made to consume such entity.
+  Contributed by Oleg Kalnichevski <olegk at apache.org>
+
 * [HTTPCLIENT-1305] Ensure chunking is disabled when applying Base64 encoding.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java?rev=1440671&r1=1440670&r2=1440671&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java
Wed Jan 30 21:12:38 2013
@@ -73,8 +73,9 @@ public class ResponseContentEncoding imp
             final HttpContext context) throws HttpException, IOException {
         HttpEntity entity = response.getEntity();
 
-        // It wasn't a 304 Not Modified response, 204 No Content or similar
-        if (entity != null) {
+        // entity can be null in case of 304 Not Modified, 204 No Content or similar
+        // check for zero length entity.
+        if (entity != null && entity.getContentLength() != 0) {
             Header ceheader = entity.getContentEncoding();
             if (ceheader != null) {
                 HeaderElement[] codecs = ceheader.getElements();

Modified: httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java?rev=1440671&r1=1440670&r2=1440671&view=diff
==============================================================================
--- httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java
(original)
+++ httpcomponents/httpclient/branches/4.2.x/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java
Wed Jan 30 21:12:38 2013
@@ -84,6 +84,21 @@ public class TestResponseContentEncoding
     }
 
     @Test
+    public void testGzipContentEncodingZeroLength() throws Exception {
+        final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
+        final StringEntity original = new StringEntity("");
+        original.setContentEncoding("GZip");
+        response.setEntity(original);
+        final HttpContext context = new BasicHttpContext();
+
+        final HttpResponseInterceptor interceptor = new ResponseContentEncoding();
+        interceptor.process(response, context);
+        final HttpEntity entity = response.getEntity();
+        Assert.assertNotNull(entity);
+        Assert.assertTrue(entity instanceof StringEntity);
+    }
+
+    @Test
     public void testXGzipContentEncoding() throws Exception {
         HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
         StringEntity original = new StringEntity("encoded stuff");



Mime
View raw message