fix: add support for gzipped content in http error stream (#134)

When the HTTP server responded with an error (statusCode >= 400),
the readResponseStream didn't decode the inStream as gzip even if
the request sended had the Content-Encoding header.

My fix moves the code that parses Content-Encoded header and
decodes gzipped body out the test to get the input stream to the
point where we are certain that we have a inStream that we can
decode.
This commit is contained in:
Reinaldo Antonio Camargo Rauch
2018-09-11 10:09:19 -03:00
committed by Manol Donev
parent 6211db3d1c
commit ebcda8e4d3

View File

@@ -388,23 +388,10 @@ public class Async
{
int contentLength = connection.getContentLength();
InputStream inStream;
if (this.statusCode >= 400)
{
inStream = connection.getErrorStream();
}
else
{
inStream = connection.getInputStream();
// In the event we don't have a null stream, and we have gzip as part of the encoding
// then we will use gzip to decode the stream
if (inStream != null) {
String encodingHeader = connection.getHeaderField("Content-Encoding");
if (encodingHeader != null && encodingHeader.toLowerCase().contains("gzip")) {
inStream = new GZIPInputStream(inStream);
}
}
}
InputStream inStream =
this.statusCode >= 400
? connection.getErrorStream()
: connection.getInputStream();
if (inStream == null)
{
@@ -413,6 +400,13 @@ public class Async
return;
}
// In the event we don't have a null stream, and we have gzip as part of the encoding
// then we will use gzip to decode the stream
String encodingHeader = connection.getHeaderField("Content-Encoding");
if (encodingHeader != null && encodingHeader.toLowerCase().contains("gzip")) {
inStream = new GZIPInputStream(inStream);
}
openedStreams.push(inStream);
BufferedInputStream buffer = new BufferedInputStream(inStream, 4096);