Hello,
I'm running into the same issue that happened in #908 which was supposed to have been solved already, but it's occurring for me now on the latest v1.16.2. Trying to do a setHeader on the passed in proxyReq for a POST requests fails with:
Error: Can't set headers after they are sent.
It's happening for both node 4.3.2 and 6.1.0.
To reproduce:
proxy.on('proxyReq', function(proxyReq, req, res, options) {
proxyReq.setHeader('origin', 'https://example.com');
});
Thank you.
I've found a workaround:
proxyReq.headers = proxyReq.headers || {}
proxyReq.headers['x-my-header'] = 'value'
Most of the times the problem is because you're subscribed to the events more than once. proxy.once('proxyReq,…) usually solves the problem guys.
I would like to change headers and path on proxyReq like the following code
proxyReq.path="/abcd/abc"
It works well with GET requests but it doesn't with POST requests
in post requests _headerSent is true
In my case the problem was an Expect: 100-continue header sent by the client. See https://github.com/http-party/node-http-proxy/issues/1219
Most helpful comment
Most of the times the problem is because you're subscribed to the events more than once.
proxy.once('proxyReq,…)usually solves the problem guys.