2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-14 18:42:33 +03:00

fix: fixed Brotli decompression; (#5353)

test: added decompression tests;
fix: added legacy `x-gzip` & `x-compress` encoding types;
This commit is contained in:
Dmitriy Mozgovoy
2022-12-07 20:57:02 +02:00
committed by GitHub
parent 56e9ca1a86
commit 1e58a659ec
3 changed files with 85 additions and 31 deletions
+8 -1
View File
@@ -23,6 +23,11 @@ import EventEmitter from 'events';
const zlibOptions = {
flush: zlib.constants.Z_SYNC_FLUSH,
finishFlush: zlib.constants.Z_SYNC_FLUSH
};
const brotliOptions = {
flush: zlib.constants.BROTLI_OPERATION_FLUSH,
finishFlush: zlib.constants.BROTLI_OPERATION_FLUSH
}
const isBrotliSupported = utils.isFunction(zlib.createBrotliDecompress);
@@ -417,7 +422,9 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
switch (res.headers['content-encoding']) {
/*eslint default-case:0*/
case 'gzip':
case 'x-gzip':
case 'compress':
case 'x-compress':
case 'deflate':
// add the unzipper to the body stream processing pipeline
streams.push(zlib.createUnzip(zlibOptions));
@@ -427,7 +434,7 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
break;
case 'br':
if (isBrotliSupported) {
streams.push(zlib.createBrotliDecompress(zlibOptions));
streams.push(zlib.createBrotliDecompress(brotliOptions));
delete res.headers['content-encoding'];
}
}
+1
View File
@@ -43,6 +43,7 @@ const isStandardBrowserEnv = (() => {
const isStandardBrowserWebWorkerEnv = (() => {
return (
typeof WorkerGlobalScope !== 'undefined' &&
// eslint-disable-next-line no-undef
self instanceof WorkerGlobalScope &&
typeof self.importScripts === 'function'
);