mirror of
https://github.com/tenrok/axios.git
synced 2026-06-08 17:22:34 +03:00
Adding option to disable automatic decompression (#2661)
* Adding ability to disable auto decompression * Updating decompress documentation in README * Fixing test\unit\adapters\http.js lint errors * Adding test for disabling auto decompression * Removing changes that fixed lint errors in tests * Removing formating change to unit test Co-authored-by: Xianming Zhong <chinesedfan@qq.com>
This commit is contained in:
committed by
GitHub
parent
6642ca9aa1
commit
42eb9dfabc
+15
-10
@@ -181,20 +181,25 @@ module.exports = function httpAdapter(config) {
|
||||
|
||||
// uncompress the response body transparently if required
|
||||
var stream = res;
|
||||
|
||||
// return the last request in case of redirects
|
||||
var lastRequest = res.req || req;
|
||||
|
||||
switch (res.headers['content-encoding']) {
|
||||
/*eslint default-case:0*/
|
||||
case 'gzip':
|
||||
case 'compress':
|
||||
case 'deflate':
|
||||
// add the unzipper to the body stream processing pipeline
|
||||
stream = (res.statusCode === 204 || lastRequest.method === 'HEAD') ? stream : stream.pipe(zlib.createUnzip());
|
||||
|
||||
// remove the content-encoding in order to not confuse downstream operations
|
||||
delete res.headers['content-encoding'];
|
||||
break;
|
||||
// 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':
|
||||
case 'compress':
|
||||
case 'deflate':
|
||||
// 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'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var response = {
|
||||
|
||||
Reference in New Issue
Block a user