compression icon indicating copy to clipboard operation
compression copied to clipboard

Move the res.write interception into a separate repo

Open dougwilson opened this issue 10 years ago • 9 comments

It needs to be in it's own repo so it can be well-tested and not need tests polluting this library.

dougwilson avatar Jun 04 '14 03:06 dougwilson

Love this move.

aredridel avatar Jul 22 '14 02:07 aredridel

So just if you were wondering, @aredridel , the idea is to provide a through stream-like interface as well as a buffered-up interface, not only for use in this library, but for use to do things like re-write links in HTML responses. It would also take care of altering the headers like Content-Length for you so they are actually correct.

dougwilson avatar Jul 22 '14 02:07 dougwilson

That sounds like my use cases! Security hacks, link rewrites, compression, verification trailers, all kinds of uses.

aredridel avatar Jul 22 '14 02:07 aredridel

All very important uses indeed. The main reason this alters a res is for compatibility with the middleware pattern as well as avoiding the complications of needing to re-implement core functionality or needing to jump through hoops to delegate correctly. This stuff that is coming is extremely well tested and builds off the current Node.js core expertise :)

dougwilson avatar Jul 22 '14 02:07 dougwilson

Can't happen soon enough. Another use case: output validation. Any sort of tentative timeline?

tlivings avatar Jul 24 '14 01:07 tlivings

Any sort of tentative timeline?

Just time-dependent. It's also not easy to get right; there are so many edge cases. I also need it very much :)

dougwilson avatar Jul 24 '14 01:07 dougwilson

Any updates on this? I need this for a bandwidth monitoring middleware I'm working on. For now, I resorted to copy-pasting the code from here :/

olalonde avatar Nov 21 '15 10:11 olalonde

I've started working on something for my own middleware: https://github.com/strongloop/express/issues/2811#issuecomment-158633664

Would be nice to see if it works with this module. Eventually we could extract the patch(res) procedure to a standalone middleware that needs to be used before response transform stream middlewares like this one. e.g.:

import responseUse from 'response-use';
app.use(responseUse);
app.use(compression);

The compression module could add itself to the list of transform stream with res.use(compressionStream) instead of having to patch res.write/res.end.

Let me know your thoughts.

olalonde avatar Nov 21 '15 12:11 olalonde

Created a repo here: https://github.com/olalonde/express-transform

olalonde avatar Nov 21 '15 12:11 olalonde