-
-
Notifications
You must be signed in to change notification settings - Fork 239
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
Allow users to pass in their own compression-stream function #59
Comments
Cool. This library cannot take a dependency on a native addon, due to the situation of native addons and Windows, making it really hard for people to use. But, I do want to increase the flexibility of this module such that users can define their own encodings, like |
Huh, it looks like that module you referenced, |
can you elaborate on this? |
When you install Node.js, running This has been a major issue for years & years and no real progress towards addressing. For example, a standard Node.js install on my machine, when I try to install your
Just installing Python onto Windows (not a simple task) is only the start. Users then have to figure out how to get the correct version of Visual Studio installed, get the proper environment variables setup so gyp works, etc. It's pretty much an impossible task for all people starting on Node.js on Windows. |
Isn't this also the case with OSX as command line tools aren't installed by default? |
I'm not familiar with Mac OS X, but I can say that when I had a module that has a native dependency, I only got endless Windows users making issue reports, but no Mac OS X or Linux users, so there is some large disconnect between those two populations of developers. You can even find dozens of issues in the Node.js repository (like nodejs/node-v0.x-archive#8005) expressing the issue of how hard it is for typical Windows developers to use native modules. I don't see any of that in the Node.js repo from Mac OS X users. |
P.S. as far as I can tell, that |
It looks like there is a native addon https://www.npmjs.com/package/iltorb that provides
|
Nice!
|
I'll work on this today, so far I have the tests: diff --git a/test/compression.js b/test/compression.js
index 26e0ca2..87abbd2 100644
--- a/test/compression.js
+++ b/test/compression.js
@@ -3,6 +3,7 @@ var bytes = require('bytes');
var crypto = require('crypto');
var http = require('http');
var request = require('supertest');
+var stream = require('stream');
var compression = require('..');
@@ -492,6 +493,40 @@ describe('compression()', function(){
})
})
+ describe('when "Accept-Encoding: custom"', function () {
+ it('should not use content encoding without a custom compressor function', function (done) {
+ var server = createServer({ threshold: 0 }, function (req, res) {
+ res.setHeader('Content-Type', 'text/plain')
+ res.end('hello, world')
+ })
+
+ request(server)
+ .get('/')
+ .set('Accept-Encoding', 'custom')
+ .expect(shouldNotHaveHeader('Content-Encoding'))
+ .expect(200, 'hello, world', done)
+ })
+
+ it('should use content encoding with a custom compressor function', function (done) {
+ var compressor = new stream.Transform
+ var opts = {
+ threshold: 0,
+ compressor: {
+ 'bingo': compressor
+ }
+ }
+ var server = createServer(opts, function (req, res) {
+ res.setHeader('Content-Type', 'text/plain')
+ res.end('hello, world')
+ })
+
+ request(server)
+ .get('/')
+ .set('Accept-Encoding', 'bingo, gzip')
+ .expect('Content-Encoding', 'bingo', done)
+ })
+ })
+
describe('when "Cache-Control: no-transform" response header', function () {
it('should not compress response', function (done) {
var server = createServer({ threshold: 0 }, function (req, res) {
|
So here's an issue I'm running into. Firefox 44 (currently Firefox Nightly) sends the header: I propose that if the consumer of this lib specifies a custom encoding, we choose that, otherwise defer to |
I added this to my PR |
Maybe this can help: |
Howdy! I'm Kenji Baheux, product manager on the web platform team @ Chrome and helping the Brotli team. We discussed about trying to get Brotli in Node core but felt that it would be hard given the sense that core is too big. However, it doesn't seem to be a blocker based on this comment. The iltorb module seems to be the best route. Are you blocked? Best, Note: Brotli is enabled by default in Chrome 51 (current stable). |
Hi @KenjiBaheux, the only blocker here is that from Express.js rules for the widest support, we need one of the following to be implemented:
I hope this helps! |
Regarding route #3, iltorb just had some major refactorings that I think allow for this. I'm not pursing this anymore, but maybe @MayhemYDG or @addaleax could help. |
oh, missed the note about pure JS. good luck with that! |
Doug, thanks for the quick reply. It's a tough one :)
We were wondering if the following option would be more practical:
Thoughts? *: for dynamic assets, lower Brotli levels are recommended for speed reasons but it would still outperform gzip compression. |
Would it help if iltorb offered pre-built binary fallbacks? I don't know how to go about that however. |
Oh, hi everyone! I think for iltorb to be used here requires adding a I wouldn’t discard option 2 completely, either, but for now that’s probably off limits just because the brotli C API isn’t nearly as stable as the ones of other Node core dependencies right now. Also, other core collaborators tend to be more concerned about feature bloat than I am. @MayhemYDG I do that for my lzma-native, so I have some experience with it. |
https://twitter.com/rvagg/status/748114279685988352 |
iltorb now offers pre-built binaries, and features a |
It looks like FF now accepts brotli compression. I was going to take a stab at implementing a native addon that links libbrotli. Does that seem worthwhile?
We could use this: https://www.npmjs.com/package/brotli, which uses an emscriptenized version of brotli.
Does anyone know of any others brotli modules that could be used? Otherwise, I don't mind starting the C++ add on.
I've been taking a look at how the gzip stream is used here, so I think I can make a nice library that implements the same interface.
The text was updated successfully, but these errors were encountered: