If I use http-proxy only as requester, there is a problem with 100-continue.
When we have a response from server with status 100 the requester in http-proxy (proxyReq in web-incoming) do not handle event "continue" and "socket hang up"
The "proxyReq" callback is invoked too late to apply additional headers.
Would it be possible to set request headers after the proxyReq event callback? Or perhaps detect whether Expect: 100-continue is included in the request headers and delay forwarding that header until after the proxyReq event callback has been processed?
As a workaround, I currently set all my headers on the incoming request object inside the HTTP server's "request" event callback. That way they get copied onto the outgoing proxied request before the Expect: 100-continue header is processed for the outgoing request.
This is my workaround, maybe it helps someone:
const proxy = httpProxy.createProxyServer({
// ...
});
proxy.before('web', 'stream', (req, res, options) => {
if (req.headers.expect) {
req.__expectHeader = req.headers.expect;
delete req.headers.expect;
}
});
proxy.on('proxyReq', (proxyReq, req, res, options) => {
// edit proxy request headers with proxyReq.setHeader(...) and proxyReq.removeHeader(...)
if (req.__expectHeader) {
proxyReq.setHeader('Expect', req.__expectHeader);
}
});
proxy.listen(3000);
Anything new on this ?
Most helpful comment
This is my workaround, maybe it helps someone: