diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index b691bd6a5..01bbf2e7c 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,7 +1,11 @@ Changes since 4.3 ALPHA1 ------------------- -* [HTTPCLIENT-1313] Fixed IllegalStateException in deprecated ThreadSafeClientConnManager +* [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 + +* [HTTPCLIENT-1313] Fixed IllegalStateException in deprecated ThreadSafeClientConnManager. Contributed by Oleg Kalnichevski * [HTTPCLIENT-1305] Ensure chunking is disabled when applying Base64 encoding. diff --git a/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java b/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java index c2ab43b46..a71c1a113 100644 --- a/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java +++ b/httpclient/src/main/java/org/apache/http/client/protocol/ResponseContentEncoding.java @@ -73,8 +73,9 @@ public class ResponseContentEncoding implements HttpResponseInterceptor { final HttpContext context) throws HttpException, IOException { final 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) { final Header ceheader = entity.getContentEncoding(); if (ceheader != null) { final HeaderElement[] codecs = ceheader.getElements(); diff --git a/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java b/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java index 7025284b4..796e14276 100644 --- a/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java +++ b/httpclient/src/test/java/org/apache/http/client/protocol/TestResponseContentEncoding.java @@ -82,6 +82,21 @@ public class TestResponseContentEncoding { Assert.assertTrue(entity instanceof GzipDecompressingEntity); } + @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 { final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");