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

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1440673 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-01-30 21:13:02 +00:00
parent e37f99ccda
commit 1f7b7a32af
3 changed files with 23 additions and 3 deletions

View File

@ -1,7 +1,11 @@
Changes since 4.3 ALPHA1 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 <olegk at apache.org>
* [HTTPCLIENT-1313] Fixed IllegalStateException in deprecated ThreadSafeClientConnManager.
Contributed by Oleg Kalnichevski <olegk at apache.org> Contributed by Oleg Kalnichevski <olegk at apache.org>
* [HTTPCLIENT-1305] Ensure chunking is disabled when applying Base64 encoding. * [HTTPCLIENT-1305] Ensure chunking is disabled when applying Base64 encoding.

View File

@ -73,8 +73,9 @@ public class ResponseContentEncoding implements HttpResponseInterceptor {
final HttpContext context) throws HttpException, IOException { final HttpContext context) throws HttpException, IOException {
final HttpEntity entity = response.getEntity(); final HttpEntity entity = response.getEntity();
// It wasn't a 304 Not Modified response, 204 No Content or similar // entity can be null in case of 304 Not Modified, 204 No Content or similar
if (entity != null) { // check for zero length entity.
if (entity != null && entity.getContentLength() != 0) {
final Header ceheader = entity.getContentEncoding(); final Header ceheader = entity.getContentEncoding();
if (ceheader != null) { if (ceheader != null) {
final HeaderElement[] codecs = ceheader.getElements(); final HeaderElement[] codecs = ceheader.getElements();

View File

@ -82,6 +82,21 @@ public class TestResponseContentEncoding {
Assert.assertTrue(entity instanceof GzipDecompressingEntity); 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 @Test
public void testXGzipContentEncoding() throws Exception { public void testXGzipContentEncoding() throws Exception {
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");