senchalabs/connect — Issue #464: Standard way to intercept the next() response
Author: dobesv
Created: 2012-01-23 05:52:41+00:00
State: open

Often middleware created for connect wants to intercept the response written by the call to next() and do their own thing with it. Compress it, store, whatever. Currently connect doesn't obviously provide an API to help with this, and people just replace the writeHead, write, end, next, setHeader, etc. on methods in the res object they are given.

The same goes for modifying or replacing the request - you have to store the previous values and insert your own values and methods when you make the call.

This approach seems a bit inelegant. In some other middlewares you have the opportunity to pass your own (req, res) to the next handler in the chain, which seems quite nice for this purpose.

What is the current thinking around having middleware that "intercepts" the request/reponse use some common methods provided by connect itself to simplify this process?

For example I created this utility method:

https://gist.github.com/1661009

But after looking at it I thought there should probably be one of these built right into connect, no? Or did I just miss it?