Skip to content

Commit

Permalink
fix: no Brotli decompression on empty HEAD response
Browse files Browse the repository at this point in the history
  • Loading branch information
barjin committed Nov 20, 2024
1 parent eea94e5 commit 1c4772d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/hooks/fix-decompress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,22 @@ const onResponse = (response: IncomingMessage, propagate: (fixedResponse: Incomi
}
});
} else if (encoding === 'br') {
useDecompressor(zlib.createBrotliDecompress());
let read = false;

response.once('data', (chunk: Buffer) => {
read = true;

response.unshift(chunk);

const decompressor = zlib.createBrotliDecompress();
useDecompressor(decompressor);
});

response.once('end', () => {
if (!read) {
propagate(response);
}
});
} else {
propagate(response);
}
Expand Down

0 comments on commit 1c4772d

Please sign in to comment.