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

fix: decompress response data #5300

Open
wants to merge 3 commits into
base: v1.x
Choose a base branch
from
Open
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: 5 additions & 1 deletion lib/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
if (config.decompress !== false) {
// if no content, but headers still say that it is encoded,
// remove the header not confuse downstream operations
if ((!responseLength || res.statusCode === 204) && res.headers['content-encoding']) {
if (
(!responseLength || res.statusCode === 204) &&
res.headers['content-encoding'] &&
!res.headers['transfer-encoding']
) {
delete res.headers['content-encoding'];
}

Expand Down
22 changes: 22 additions & 0 deletions test/unit/adapters/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,28 @@ describe('supports http with nodejs', function () {
})
});

it('should support decompression of response data', function(done) {
var data = 'Test data';

zlib.gzip(data, function(err, zipped) {
server = http.createServer(function(req, res) {
res.setHeader('Content-Type', 'text/html;charset=utf-8');
res.setHeader('Content-Encoding', 'gzip');
res.setHeader('Transfer-Encoding', 'chunked');
res.end(zipped);
}).listen(4444, function() {
axios.get('http://localhost:4444/', {
decompress: true,
responseType: 'arraybuffer'

}).then(function(res) {
assert.equal(res.data, data);
done();
}).catch(done);
});
});
});

it('should support disabling automatic decompression of response data', function(done) {
var data = 'Test data';

Expand Down