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