only enable Z_SYNC_FLUSH for gzip response

This commit is contained in:
David Frank 2017-05-15 19:45:04 +08:00
parent 2a1a565641
commit 770388db1b
1 changed files with 3 additions and 2 deletions

View File

@ -141,6 +141,7 @@ export default function fetch(url, opts) {
return;
}
// For Node v6+
// Be less strict when decoding compressed responses, since sometimes
// servers send slightly invalid responses that are still accepted
// by common browsers.
@ -165,9 +166,9 @@ export default function fetch(url, opts) {
raw.once('data', chunk => {
// see http://stackoverflow.com/questions/37519828
if ((chunk[0] & 0x0F) === 0x08) {
body = body.pipe(zlib.createInflate(zlibOptions));
body = body.pipe(zlib.createInflate());
} else {
body = body.pipe(zlib.createInflateRaw(zlibOptions));
body = body.pipe(zlib.createInflateRaw());
}
resolve(new Response(body, response_options));
});