-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Brotli transparent support #443
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented
@@ -7,7 +7,9 @@ | |||
"mocha": true, | |||
}, | |||
"globals": {}, | |||
"parserOptions": { "ecmaVersion": 8 }, | |||
"parserOptions": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All formatting changes here are automated by the ESlint plugin in my editor
@@ -150,7 +160,10 @@ | |||
], | |||
"lines-around-comment": [ | |||
2, | |||
{ "afterLineComment": true, "allowBlockEnd": true } | |||
{ | |||
"afterLineComment": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this because the existing code wasn't following this rule (and also I think it's fairly common to have no empty line between a single line comment and the next line it explains)
@@ -37,11 +60,11 @@ function verifyBuffer(rspd, reject) { | |||
|
|||
function updateHeaders(res, rspdBefore, rspdAfter, reject) { | |||
if (!res.headersSent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Automatically formatted, it looks like 4 spaces were used
}); | ||
}; | ||
} | ||
|
||
var maybeUnzipPromise = zipOrUnzip('gunzip'); | ||
var maybeZipPromise = zipOrUnzip('gzip'); | ||
function createEncodingHandler(res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously, this is the central part
@@ -10,9 +10,9 @@ function asBuffer(body, options) { | |||
if (Buffer.isBuffer(body)) { | |||
ret = body; | |||
} else if (typeof body === 'object') { | |||
ret = new Buffer(JSON.stringify(body), options.reqBodyEncoding); | |||
ret = Buffer.from(JSON.stringify(body), options.reqBodyEncoding); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer constructor is deprecated and the from
method is available in node v6+ so it shouldn't be a breaking change. Fixed it to remove the warnings during the tests
var request = require('supertest'); | ||
// superagent/supertest don't support `br` encoding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!
@@ -169,13 +176,111 @@ describe('userResDecorator', function () { | |||
request(proxyApp) | |||
.get('/') | |||
.expect(function (res) { | |||
res.headers.location.match(/localhost:3000/); | |||
assert(res.headers.location.match(/localhost:3000/)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume it was missing here. Didn't check other tests
beforeEach(function () { | ||
app = express(); | ||
target = express(); | ||
target.use(compression({ threshold: 0 })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The threshold ensures the small payload is still gzip-encoded
|
||
request(app) | ||
.get('/proxy/test') | ||
.set('Accept-Encoding', 'gzip') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enforce gzip
// with the original binary data | ||
encoding: null, | ||
headers: { | ||
'Accept-Encoding': 'br' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enforce brotli
Huh, the |
I'll leave a couple of comments to justify some non-obvious changes