Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not pipe stream to gunzip with HEAD request. #1384

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ module.exports = function httpAdapter(config) {
case 'gzip':
case 'compress':
case 'deflate':
// add the unzipper to the body stream processing pipeline
stream = stream.pipe(zlib.createUnzip());
if (options.method !== 'head') {
// add the unzipper to the body stream processing pipeline
stream = stream.pipe(zlib.createUnzip());
}

// remove the content-encoding in order to not confuse downstream operations
delete res.headers['content-encoding'];
Expand Down
14 changes: 14 additions & 0 deletions test/unit/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,20 @@ module.exports = {
});
},

testTransparentGunzipSkipHead: function (test) {
server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'application/json;charset=utf-8');
res.setHeader('Content-Encoding', 'gzip');
res.end();
}).listen(4444, function () {
axios.head('http://localhost:4444/').then(function (res) {
test.done();
}).catch(function (err) {
test.done(err);
});
});
},

testGunzipErrorHandling: function (test) {
server = http.createServer(function (req, res) {
res.setHeader('Content-Type', 'application/json;charset=utf-8');
Expand Down