onProxyReq not fired
See original GitHub issueIs this a bug report?
Yes.
Expected behavior
onProxyReq
runs, allowing me to modify the request.
Actual behavior
onProxyReq
is not run when a body is included in the request message, when C#'s HttpClient is used to issue the request.
The setup here is a little non-standard. I have a C# client that uses HttpClient. It makes a request which goes to a node server running http-proxy-middleware.
HttpClient is adding an Expect
header for some reason – something it is entitled to do, but which browser don’t do. Usually, an Expect
header indicates that we’re doing a 100-continue
type hand signal. Microsoft’s implementation of HttpClient is presumably correct. Developers are not supposed to be explicitly modifying the Expect
header.
When I issue a POST
with no body, onProxyReq
is fired. But when I issue a POST
with a body, onProxyReq
is never fired. I traced this to one of the latest commits in node-http-proxy
– link. The problem is fixed if that change is undone.
I don’t see any reason why they changed this upstream.
It’s not clear to me what actions I can take to make http-proxy-middleware
proxy my requests that have bodies. I can’t modify the implementation or usage of HttpClient
, only the server.
I have sizable headers, but the request body itself can be as short as “{}” in order to trigger this bug.
Setup
- http-proxy-middleware: 1.0.6
- http-proxy-middleware configuration
app.use(`/mypath`, createProxyMiddleware({
target: 'http://foobar.com',
changeOrigin: true,
headers: {
'X-Custom-Header': 'foobar'
},
preserveHeaderKeyCase: true,
logLevel: 'debug'
onProxyReq(proxyReq, req, res) {
console.log('onProxyReq was fired');
}
}));
- server: express 4.17.1
client info
.NET 4.7.2’s HttpClient
target server info
Target agnostic – I’ve pointed it at an express server that just prints out information about requests that it receives.
Reproducible Demo
No demo at the moment.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top GitHub Comments
I forget how it’s related to this precise issue, and exactly what that codebase contained, but I did get my proxy server running. I had to check for the Expect header and strip it; use body-parser in the raw mode to then later copy the body onto the proxied request. I also had to run node 14, and start the server using the extra options argument to http(s).createServer(options, app), specifying the node-14-only max-header size property to be much larger.
I seem to have moved past this/worked around it, but I really don’t remember more details; I apologize.
Edit: I remember also possibly specifying older versions of the libraries involved, but not if that was included in the final solution.
I know it’s been months. But there’s a workaround here https://github.com/http-party/node-http-proxy/issues/1219, but I’m not sure if it’s the right solution. Regardless, is there any way for us to access the http-proxy directly from HPM?