-
Notifications
You must be signed in to change notification settings - Fork 852
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
feat: try to proxy body even after body-parser middleware #492
Conversation
Congratulations 🎉. DeepCode analyzed your code in 3.34 seconds and we found no issues. Enjoy a moment of no bugs ☀️. 👉 View analysis in DeepCode’s Dashboard | Configure the bot |
439832f
to
e94517a
Compare
Thanks @midgleyc for this PR. (Sorry for late reply) Could you separate And maybe rename This'll make It's usage will be like this: const { createProxyMiddleware, fixRequestBody } = require('http-proxy-middleware');
const proxy = createProxyMiddleware({
/**
* Fix bodyParser
**/
onProxyReq: fixRequestBody,
}); Planning to work on a |
ab2dc66
to
6f79a44
Compare
@chimurai Done, how does it look now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's quick :)
Could you add some documentation before or after:
https://github.com/chimurai/http-proxy-middleware/blob/master/README.md#intercept-and-manipulate-responses
Changes made. You should be able to make changes to my branch directly, if you'd like. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Thanks @midgleyc ! |
You're welcome, thanks for merging :) |
This workaround doesn't seem to work for my case. In later versions, the proxyReq etc. are set inside the on property:
In my case I have an https proxy agent as well in the options (without that I don't even need to try the workaround!). Unfortunately I need that as my server runs inside company network and needs to go via proxy to the target. In such a set-up, I get an error in the fixRequestBody method (where it sets the content type header), and is says (something like) 'cannot change headers after they are sent to the client'. Specifically the error is:
Basically, it seems that the proxyReq isn't able to modify the headers, which seems to largely defeat the point of this 'hook' (in my case at least)..... |
@dhurtrci Can you please open a new issue and provide a reproduction so it can be investigated? |
If a body parser middleware is added before the proxy is configured, proxying POST requests with bodies fails. This fixes that and provides a test, as requested by @chimurai in #460.
Code from #460 by @sarumont and from #320 by @repl-chris used -- thanks to both!
Fixes #90
Fixes #320
Fixes #417