So I did something like this (pseudocode), works pretty well. I am currently using it to transparently cache requests. This would be *so* much easier if google groups supported markdown like github.
// config includes what to call next in the chain, ttl for my cache, and a secret key to flush the cache remotely, etc. In one instance, I have a list of regex for which to invoke on the URL module.exports = function(config) { return function(req,res,next) { wrapResponse(res); // do the next thing }; }; wrapResponse looks like: wrapResponse = function(res) { write = res.write, writeHead = res.writeHead, setHeader = res.setHeader, removeHeader = res.removeHeader, end = res.end; res.write = function(chunk,encoding) { // do what you want with it, like caching write.apply(this,arguments); }; }; The above is generic, but I turned it into a nice performant in-memory caching module to wrap node-http-proxy. Variable ttl, and external flushable. On Wednesday, February 20, 2013 10:50:12 PM UTC+2, deitch wrote: > > Just introspection. I am happy to let it go along its way in both > directions, as long as I can peek in and see what data passes. > > On Wednesday, February 20, 2013 10:42:59 PM UTC+2, greelgorke wrote: >> >> it's not clear how/what for you want to utilize the response. >> introspection? manipulation? >> >> Am Mittwoch, 20. Februar 2013 21:05:35 UTC+1 schrieb deitch: >>> >>> Yeah, I should have been more clear, shouldn't I? >>> >>> Adding handling to node-http-proxy. It takes as its input the >>> (request,response) pair from an http server callback handler. I want to >>> wrap it so I can cache as well as some other processing. >>> >>> Normal http operation looks like this: >>> >>> Client ----> Node >>> >>> Proxy operation looks like this >>> >>> Client ----> Node (running node-http-proxy) ----> Remote service >>> >>> What I am trying to do: >>> >>> >>> Client ----> Node (running my handler, passes to node-http-proxy) ----> >>> Remote service >>> >>> It is easier to get in front of the request; I want to be able to >>> instrument the response. >>> >>> Is that clearer? >>> >>> >>> >>> On Wednesday, February 20, 2013 9:24:21 PM UTC+2, greelgorke wrote: >>>> >>>> what exactly are you trying to do? of course you can always wrap >>>> anything and observe actions etc., but it's not the problem you're trying >>>> to solve in first place, right? >>>> >>>> Am Mittwoch, 20. Februar 2013 16:46:31 UTC+1 schrieb deitch: >>>>> >>>>> Is there any way to wrap http.serverResponse? >>>>> >>>>> E.g. I am using a module that takes as its input http.serverRequest >>>>> and http.serverResponse. I want to be able to transparently catch any >>>>> actions that the module performs on http.serverResponse so I can cache >>>>> the >>>>> statusCode, header and response. >>>>> >>>>> Do I have to override each and every major function - write, >>>>> writeHead, end, setHeader, removeHeader - to do so? Is there a simpler >>>>> way? >>>>> I thought about looking for some 'end' type event, but that would miss >>>>> all >>>>> of the streaming data. >>>>> >>>>> >>>>> -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.