-
Notifications
You must be signed in to change notification settings - Fork 849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
onProxyReq not fired #483
Comments
Probably related to #40 (comment) . Feel free to re-open if that's not the case |
This is not related, there is no other middleware. Although I have been wondering if a way to fix it may be to add middleware, for example by installing I investigated more on what I mentioned, about reverting the change in node-http-proxy. It turns out, while I thought that "fixed" things, it simply fixes one part of things. It is looking like |
Looks like it's indeed an upstream lib issue. Nothing I can really do from HPM perspective. |
I know it's been months. But there's a workaround here http-party/node-http-proxy#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? |
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. |
follow the solution in http-party/node-http-proxy#1219 , We should delete the req.headers.expect and add it back in onProxyReq function and it works!!!! if ((req.headers || {}).expect) {
req.__expectHeader = req.headers.expect;
delete req['headers'].expect;
} onProxyReq if (req.__expectHeader) {
proxyReq.setHeader('Expect', req.__expectHeader)
} |
@radiorz if ((req.headers || {}).expect) {
req.__expectHeader = req.headers.expect;
delete req['headers'].expect;
} As we are using http-proxy-middleware, this is (basically) my current usage: export function setupProxies(app, r) {
app.use(r.url, createProxyMiddleware(r.proxyOptions));
};
} And in my main file i call it like: import express from 'express';
const app = express();
setupProxies(app, ROUTES); I tried deleting the header like so: app.use(deleteExpectHeader);
var deleteExpectHeader = function (req: Request, res: Response) {
if (req.headers.expect) {
delete req.headers.expect;
}
}; No luck with this. Any help is much appreciated. |
Answered my own question: I had to call the "deleteExceptHeader" middleware before the "setupProxies". |
Is 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, anExpect
header indicates that we're doing a100-continue
type hand signal. Microsoft's implementation of HttpClient is presumably correct. Developers are not supposed to be explicitly modifying theExpect
header.When I issue a
POST
with no body,onProxyReq
is fired. But when I issue aPOST
with a body,onProxyReq
is never fired. I traced this to one of the latest commits innode-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 ofHttpClient
, only the server.I have sizable headers, but the request body itself can be as short as "{}" in order to trigger this bug.
Setup
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.
The text was updated successfully, but these errors were encountered: