Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

emirotin
Copy link

I'll leave a couple of comments to justify some non-obvious changes

Copy link
Author

@emirotin emirotin left a 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": {
Copy link
Author

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,
Copy link
Author

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) {
Copy link
Author

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) {
Copy link
Author

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);
Copy link
Author

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
Copy link
Author

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/));
Copy link
Author

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 }));
Copy link
Author

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')
Copy link
Author

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'
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforce brotli

@emirotin
Copy link
Author

Huh, the iltorb module is using some ES6 syntax (spread) not supported in Node v6. Would it make sense to deprecate this really outdated Node version?

@emirotin emirotin mentioned this pull request Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant