mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
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:
committed by
Manol Donev
parent
6211db3d1c
commit
ebcda8e4d3
@@ -388,23 +388,10 @@ public class Async
|
|||||||
{
|
{
|
||||||
int contentLength = connection.getContentLength();
|
int contentLength = connection.getContentLength();
|
||||||
|
|
||||||
InputStream inStream;
|
InputStream inStream =
|
||||||
if (this.statusCode >= 400)
|
this.statusCode >= 400
|
||||||
{
|
? connection.getErrorStream()
|
||||||
inStream = connection.getErrorStream();
|
: connection.getInputStream();
|
||||||
}
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inStream == null)
|
if (inStream == null)
|
||||||
{
|
{
|
||||||
@@ -413,6 +400,13 @@ public class Async
|
|||||||
return;
|
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);
|
openedStreams.push(inStream);
|
||||||
|
|
||||||
BufferedInputStream buffer = new BufferedInputStream(inStream, 4096);
|
BufferedInputStream buffer = new BufferedInputStream(inStream, 4096);
|
||||||
|
|||||||
Reference in New Issue
Block a user