build: let webpack proxy server handle more content encoding (#11376)

This commit is contained in:
Jesse Yang 2020-10-22 13:25:17 -07:00 committed by GitHub
parent b89a5d6660
commit 04ee4a2d08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -109,12 +109,20 @@ function copyHeaders(originalResponse, response) {
function processHTML(proxyResponse, response) {
let body = Buffer.from([]);
let originalResponse = proxyResponse;
let uncompress;
const responseEncoding = originalResponse.headers['content-encoding'];
// decode GZIP response
if (originalResponse.headers['content-encoding'] === 'gzip') {
const gunzip = zlib.createGunzip();
originalResponse.pipe(gunzip);
originalResponse = gunzip;
if (responseEncoding === 'gzip') {
uncompress = zlib.createGunzip();
} else if (responseEncoding === 'br') {
uncompress = zlib.createBrotliDecompress();
} else if (responseEncoding === 'deflate') {
uncompress = zlib.createInflate();
}
if (uncompress) {
originalResponse.pipe(uncompress);
originalResponse = uncompress;
}
originalResponse