From 2ef127ad8ece877f6303fde7e9f3bd65749ac52b Mon Sep 17 00:00:00 2001 From: Kyle Harding Date: Fri, 27 Aug 2021 15:01:47 -0400 Subject: [PATCH] Allow more levient gzip decompression Be more lenient with decoding compressed responses, since (very rarely) servers send slightly invalid gzip responses that are still accepted by common browsers. Always using Z_SYNC_FLUSH is what cURL does. Change-type: patch Signed-off-by: Kyle Harding --- lib/progress.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/progress.js b/lib/progress.js index 18af745..2de6a41 100644 --- a/lib/progress.js +++ b/lib/progress.js @@ -126,8 +126,18 @@ export function estimate(requestAsync, isBrowser) { ); if (!isBrowser && utils.isResponseCompressed(response)) { - const { createGunzip } = require('zlib'); - const gunzip = createGunzip(); + const zlib = require('zlib'); + + // Be more lenient with decoding compressed responses, since (very rarely) + // servers send slightly invalid gzip responses that are still accepted + // by common browsers. + // Always using Z_SYNC_FLUSH is what cURL does. + var zlibOptions = { + flush: zlib.constants.Z_SYNC_FLUSH, + finishFlush: zlib.constants.Z_SYNC_FLUSH + } + + const gunzip = zlib.createGunzip(zlibOptions); // Uncompress after or before piping through progress // depending on the response length available to us