Skip to content

Commit

Permalink
Allow more levient gzip decompression
Browse files Browse the repository at this point in the history
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 <kyle@balena.io>
  • Loading branch information
klutchell committed Aug 27, 2021
1 parent 23367e9 commit 2ef127a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/progress.js
Expand Up @@ -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
Expand Down

0 comments on commit 2ef127a

Please sign in to comment.