diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt index 53e660fe5..770d8626b 100644 --- a/RELEASE_NOTES.txt +++ b/RELEASE_NOTES.txt @@ -1,6 +1,9 @@ Changes since release 4.3 BETA1 ------------------- +* [HTTPCLIENT-1341] DeflateDecompressingEntity does not call Inflater#end. + Contributed by Oleg Kalnichevski + * [HTTPCLIENT-1299] (regression) cache incorrectly disposes of the underlying cache resource when storing variant entry. Contributed by James Leigh diff --git a/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java b/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java index 39374460e..7a730431b 100644 --- a/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java +++ b/httpclient/src/main/java/org/apache/http/client/entity/DeflateDecompressingEntity.java @@ -142,13 +142,15 @@ public class DeflateDecompressingEntity extends DecompressingEntity { * and return an unused InputStream now. */ pushback.unread(peeked, 0, headerLength); - return new InflaterInputStream(pushback); + return new DeflateStream(pushback, new Inflater()); } catch (final DataFormatException e) { /* Presume that it's an RFC1951 deflate stream rather than RFC1950 zlib stream and try * again. */ pushback.unread(peeked, 0, headerLength); - return new InflaterInputStream(pushback, new Inflater(true)); + return new DeflateStream(pushback, new Inflater(true)); + } finally { + inf.end(); } } @@ -172,4 +174,24 @@ public class DeflateDecompressingEntity extends DecompressingEntity { return -1; } + static class DeflateStream extends InflaterInputStream { + + private boolean closed = false; + + public DeflateStream(final InputStream in, final Inflater inflater) { + super(in, inflater); + } + + @Override + public void close() throws IOException { + if (closed) { + return; + } + closed = true; + inf.end(); + super.close(); + } + + } + }