HTTPCLIENT-1341] DeflateDecompressingEntity does not call Inflater#end

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@1469235 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2013-04-18 09:15:00 +00:00
parent 456461b1c6
commit 68243b227f
2 changed files with 27 additions and 2 deletions

View File

@ -1,6 +1,9 @@
Changes since release 4.3 BETA1
-------------------
* [HTTPCLIENT-1341] DeflateDecompressingEntity does not call Inflater#end.
Contributed by Oleg Kalnichevski <olegk at apache.org>
* [HTTPCLIENT-1299] (regression) cache incorrectly disposes of the underlying cache resource
when storing variant entry.
Contributed by James Leigh <james at 3roundstones.com>

View File

@ -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();
}
}
}