Skip to content

Commit c6ec5fc

Browse files
Fixing Z_BUF_ERROR when no content (axios#4701)
* Fix Z_BUF_ERROR when no content * Refactored code * Fix undefined check Co-authored-by: Jay <jasonsaayman@gmail.com>
1 parent 807918b commit c6ec5fc

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/adapters/http.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,14 @@ module.exports = function httpAdapter(config) {
236236
// return the last request in case of redirects
237237
var lastRequest = res.req || req;
238238

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

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

0 commit comments

Comments
 (0)