mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-07-29 00:59:10 +00:00
Support to decompress the brotli content-encoding
This commit is contained in:
@@ -12,6 +12,7 @@ const http = require('http'),
|
||||
logUtil = require('./log'),
|
||||
co = require('co'),
|
||||
HttpsServerMgr = require('./httpsServerMgr'),
|
||||
brotliTorb = require('iltorb'),
|
||||
Readable = require('stream').Readable;
|
||||
|
||||
const requestErrorHandler = require('./requestErrorHandler');
|
||||
@@ -99,6 +100,7 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
|
||||
const contentEncoding = resHeader['content-encoding'] || resHeader['Content-Encoding'];
|
||||
const ifServerGzipped = /gzip/i.test(contentEncoding);
|
||||
const isServerDeflated = /deflate/i.test(contentEncoding);
|
||||
const isBrotlied = /br/i.test(contentEncoding);
|
||||
|
||||
/**
|
||||
* when the content is unzipped, update the header content
|
||||
@@ -133,6 +135,16 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
|
||||
fulfill(buff);
|
||||
}
|
||||
});
|
||||
} else if (isBrotlied && originContentLen) {
|
||||
refactContentEncoding();
|
||||
|
||||
brotliTorb.decompress(serverResData, (err, buff) => {
|
||||
if (err) {
|
||||
rejectParsing(err);
|
||||
} else {
|
||||
fulfill(buff);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
fulfill(serverResData);
|
||||
}
|
||||
|
Reference in New Issue
Block a user