Skip to content

Commit 6317098

Browse files
committed
Support to decompress the brotli content-encoding
1 parent ee0f285 commit 6317098

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/requestHandler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const http = require('http'),
1212
logUtil = require('./log'),
1313
co = require('co'),
1414
HttpsServerMgr = require('./httpsServerMgr'),
15+
brotliTorb = require('iltorb'),
1516
Readable = require('stream').Readable;
1617

1718
const requestErrorHandler = require('./requestErrorHandler');
@@ -99,6 +100,7 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
99100
const contentEncoding = resHeader['content-encoding'] || resHeader['Content-Encoding'];
100101
const ifServerGzipped = /gzip/i.test(contentEncoding);
101102
const isServerDeflated = /deflate/i.test(contentEncoding);
103+
const isBrotlied = /br/i.test(contentEncoding);
102104

103105
/**
104106
* when the content is unzipped, update the header content
@@ -133,6 +135,16 @@ function fetchRemoteResponse(protocol, options, reqData, config) {
133135
fulfill(buff);
134136
}
135137
});
138+
} else if (isBrotlied && originContentLen) {
139+
refactContentEncoding();
140+
141+
brotliTorb.decompress(serverResData, (err, buff) => {
142+
if (err) {
143+
rejectParsing(err);
144+
} else {
145+
fulfill(buff);
146+
}
147+
});
136148
} else {
137149
fulfill(serverResData);
138150
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"es6-promise": "^3.3.1",
2222
"express": "^4.8.5",
2323
"iconv-lite": "^0.4.6",
24+
"iltorb": "^2.0.3",
2425
"inquirer": "^3.0.1",
2526
"ip": "^0.3.2",
2627
"juicer": "^0.6.6-stable",
@@ -92,7 +93,7 @@
9293
"worker-loader": "^0.7.1"
9394
},
9495
"scripts": {
95-
"prepublish":"npm run buildweb",
96+
"prepublish": "npm run buildweb",
9697
"test": "node test.js",
9798
"lint": "eslint .",
9899
"testserver": "node test/server/startServer.js",

0 commit comments

Comments
 (0)