Added support for brotli ('br') content-encoding #172
Conversation
Make sure to update the documentation as well around it supporting br. |
@dougwilson There's an issue with |
I guess just pick a different module or an older version of that module. |
d4a01cb
to
42dacd1
d3f283f
to
d557204
I added a comment about the faster statement and still have an open question on how a user can change compression level of br. |
I added a comment about the faster statement and still have an open question on how a user can change compression level of br. I'm also having trouble to actually get br compression to even work at all with Chrome. I'm trying to figure it out, as our number 1 issue opened here is how to get this module working, so having concrete information for how to get br working with a web browser (Chrome, for instance) would help a lot. For reference I used the example in the README and your branch and Chrome continues to only show it using gzip, even when the connection is https (which my understanding is a requirement for br to work in Chrome). |
Look at Chrome's Or maybe it's because when it first arrived they considered it a good compression for WOFF fonts, but they always tested with the highest compression levels. Today people know that with level 4 you have better results on all kinds of files. |
I will make a change so that if brotli and gzip are preferred equally (regardless of order) the system will prefer brotli. Otherwise, the system will prefer the more preferred compression algorithm. Sound reasonable? |
My thinking is to not reinvent the wheel so I've pulled in koa-compress' logic to determine which content encoding header is preferred as it conforms the rules we've specified above. I've also added a test case to verify. My only concern here is node version support. What is the official node version support for this lib? |
The official Express.js middlewares support the same Node.js versions as the current version of Express.js. The Travis CI has the supported versions listed in the test matrix. |
Yea, that sounds fine to me, as it seems like that is what the web browsers are actually doing for this case. |
Forgive me as I'm not super familiar with Travis CI but according to https://expressjs.com/en/changelog/4x.html Express.js seems to only support node 10.x and 12.x but the test matrix goes all the way down to 0.8? Did I interpret something? My tests are passing with Node > 6.x. Is that sufficient? |
I think you are mistaking the change log for adding support to Node.js versions as supporting only those versions. It supports the same versions the Travis CI matrix of this module supports, so the CI just needs to pass with the existing matrix unless the idea is to hold this PR until the next major version instead of releasing as a semver minor, if that is the desire. Express 5 will be released soon, so it would probably only need to wait a few months if that is what path you want. |
Though it seems like this change has broken the accept in other ways. For example, given the header |
Ok, I have all the tests passing on all versions of node, including a new test that tests the "gzip;q=0.001" value. |
Hi @nicksrandall thank you so much! I am still on mobile, and it looks like there is now a substantial amount of code to review I think (but haven't yet tried) based on the code that it is not as standards compliant as the previous module used here, and we will need to go over this new implementation and compare to the standards with a fine-toothed comb. It seems to me that, for instance, it is not comparing the content coding as a case-insensitive manor as specified in RFC 7231 (but since I'm mobile I haven't tested that -- I am just looking at the code on a small screen If we want to move forward with this implementation, please give me until the next couple weeks to have the time to circle around to review all of this code... the first few looks I've noticed multiple spec violations, even after you made a bunch of changes, so I'm not sure at what level of detail this large replacement code has been looked over to feel comfortable sending to the 8M+ daily downloads, as we want to really be sure we are not regressing behavior here |
I didn't want to loose what was happening here so I have created an alternate PR (#173) that provides what I believe to be the absolute minimal code change to this library to support brolti in a backwards compatible way. I'm just hoping that one of these PRs gets merged in the near term. Please let me know which direction you think would be best to continue to pursue. |
@dougwilson I've removed the dependency on koa's modified code, and implemented a simple parsing function for the encoding, with built-in preferred-encoding support. this results in less code, and a faster code. Passing all old tests, new tests, and the latest ones added by @nicksrandall I really don't see anything blocking a merge now, and it would be great to have this in production :-) I've also rebased on |
I'm a bit concerned about why we should be adding such a large amount of code directly to this library, vs adding whatever is needed into Express.js's own Besides that, even just putting that code in here seems to have licensing issues, as it seems to be a large chunk of the |
This module uses I don't see a "large chunk" of Do you want to get |
It is part of Express.js: http://expressjs.com/en/resources/community.html#express-is-made-of-many-modules
Why not? I mean, just look at the person who is committing there... it is me. Are you saying I would not accept what I am suggesting you to put there?
Sure, you may have unrolled some of those functions together, but unless you are saying you definately didn't copy and paste from negotiator and just move around the code, then it is certainly the original license at play on that code. |
Good to know
I do not really get the insistency on splitting everything to a million pieces, I don't see a value to any extremity, but on the other hand I don't mind making a PR to |
@dougwilson If we're at it - why did you filter out |
This is because when you combine the module's API and spec, that is the correct functionality. The API of the module only returns what is acceptable. The spec says that 0 is a special value of not acceptable (vs just the lowest acceptability, which would be 0.001). You can find the spec in RFC 7231.
|
@dougwilson you have a PR pending |
I guess everyone are in vacation now |
expressjs/body-parser#403
https://medium.com/oyotech/how-brotli-compression-gave-us-37-latency-improvement-14d41e50fee4
https://caniuse.com/#feat=brotli