Skip to content

Commit

Permalink
Fixing Z_BUF_ERROR when no content (#4701)
Browse files Browse the repository at this point in the history
* Fix Z_BUF_ERROR when no content

* Refactored code

* Fix undefined check

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
lejahmie and jasonsaayman committed May 12, 2022
1 parent 807918b commit c6ec5fc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/adapters/http.js
Expand Up @@ -236,9 +236,14 @@ module.exports = function httpAdapter(config) {
// return the last request in case of redirects
var lastRequest = res.req || req;

// if decompress disabled we should not decompress
if (config.decompress !== false) {
// if no content, but headers still say that it is encoded,
// remove the header not confuse downstream operations
if (data && data.length === 0 && res.headers['content-encoding']) {
delete res.headers['content-encoding'];
}

// if no content, is HEAD request or decompress disabled we should not decompress
if (res.statusCode !== 204 && lastRequest.method !== 'HEAD' && config.decompress !== false) {
switch (res.headers['content-encoding']) {
/*eslint default-case:0*/
case 'gzip':
Expand Down

0 comments on commit c6ec5fc

Please sign in to comment.