node-http-proxy
node-http-proxy copied to clipboard
selfHandleResponse: true => response broken
I'm trying to manually handle the response with { selfHandleResponse: true }, but, as the doc says:
none of the webOutgoing passes are called
And that prevents me from correctly sending response.
This is the code causing the problem:
// passes/web-incoming.js
if(!res.headersSent && !options.selfHandleResponse) {
for(var i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes, options)) { break; }
}
}
Doing this, fixes it:
if(!res.headersSent) {
for(var i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes, options)) { break; }
}
}
I need to call the webOutgoing passes and do some extra stuff. But I can't.
Maybe you can expose passes/web-outgoing, or add a flag like callWebOutgoing to let users call them if they want to.
Hi, I am having the same issue. I am trying to forward a response after I have edited its body but the headers are empty.
Have you found another solution maybe?
@jcrugzz an idea maybe?
Thank you!
Hi,
I found an ugly hack actually. I copy/paste a piece of node-http-proxy's internal code, and I give credit...
const web_o = Object.values(require('http-proxy/lib/http-proxy/passes/web-outgoing'));
// ...
.on('proxyRes', (proxyRes, req, res) => {
// code taken from here: https://github.com/nodejitsu/node-http-proxy/blob/42e8e1e099c086d818d8f62c8f15ec5a8f1a6624/lib/http-proxy/passes/web-incoming.js#L174
for(var i=0; i < web_o.length; i++) {
if(web_o[i](req, res, proxyRes, options)) { break; }
}
});
Thank you @HugoMuller, gonna try that out!
The issue is not fixed yet. I want to log the response in some scenarios. But it is always empty.
@HugoMuller solution worked for me! But it would be nice if we didn't have to use that kind of hack... How would you feel about exposing some API that would allow us to utilize the web outgoing passes without the hack? If you're down with it, I can do some work and submit a PR
@HugoMuller well, where is the options param defined?
This issue is still not fixed. Is this repository still maintained?
This issue is still not fixed. Is this repository still maintained?
I suppose not, as the last commit in the master branch is nearly 4 years old now.