Created by: colinmollenhour
I am implementing a caching layer on top of http-proxy and without these changes see no good way to intercept the upstream response so that it can be stored in a cache or replace a 304 response with a 200 response or manipulate headers in a few places. None of these changes will break backwards compatibility.
Note, the caching proxy layer is fully implemented but is still in beta: colinmollenhour/node-caching-proxy
Activity
Created by: colinmollenhour
None of the tests use the arguments from the request 'end' event so no changes needed. Do you want a test that confirms that the new argument exists?
The second block of code has no effect unless there is an event observer for the proxyResponse event and that observer throws an exception. So I'm not sure how to add a test specifically for this since the outcome on an observer that does nothing is the same as no observer and the tests should not predict what the observer will do or not do. Basically if there is an observer it is up to the author of that observer to test the outcome, right?
Created by: Giuliano84
Hi @colinmollenhour, @indexzero
I'm trying to leverage proxyResponse event to modify response headers that get setted up by the proxied server. This means that the server behind the proxy put some data in an "x-cust-field" on the
res
object so and Proxy can read and process it on proxyResponse. Now I dont want this info to be sent to the client, options are: removing the field or just edit it removing sensible data.proxy.on('proxyResponse', function (req, res, response) { res.setHeader('x-new-cust-field', 'mycustomfield'); //Able to add custom headers fields res.setHeader('x-cust-field', 'editedcustomfield'); //This makes no changes in the response header //maybe I can intercept it on some response emitted events? response.on('data', function(body){ try { res.getHeader('x-cust-field') //can see all the values written by proxied server res.setHeader('x-cust-field', 'editedcustomfield'); //Can't set headers after they are sent. } catch(e){ //ERROR } }) });
I'm not sure if I should act on
res
orresponse
(the latter has no setHeader methods), this seems possible so what am I missing? ThanksCreated by: colinmollenhour
res
is the response to the client,response
is the response from upstream. however, it has been a while since I looked at this code so I don't know offhand if it is sufficient to useres.setHeader
. You might need to remove the header fromresponse
instead..