Skip to content

fix: properly proxy the body#460

Closed
sarumont wants to merge 2 commits intochimurai:masterfrom
sarumont:master
Closed

fix: properly proxy the body#460
sarumont wants to merge 2 commits intochimurai:masterfrom
sarumont:master

Conversation

@sarumont
Copy link
Copy Markdown

@sarumont sarumont commented Jul 30, 2020

Things like body-parser can break proxying anything with a body. This
checks for that (req.body will become an Object) and streams the body
into the proxy request.

Fixes #90, #320, #417 - and maybe some more

@coveralls
Copy link
Copy Markdown

coveralls commented Jul 30, 2020

Coverage Status

Coverage decreased (-0.9%) to 87.421% when pulling 691f399 on sarumont:master into 7ae82e8 on chimurai:master.

@chimurai
Copy link
Copy Markdown
Owner

chimurai commented Aug 3, 2020

Thanks for the PR.

Could you add a test as proof for this fix?

You can add body-parser to the devDependencies if needed for the test.

@ghost
Copy link
Copy Markdown

ghost commented Jan 12, 2021

DeepCode's analysis on #691f39 found:

  • ⚠️ 1 warning 👇

Top issues

Description Example fixes
The Content-Length header should be set by the browser, not in code (in setHeader). Occurrences: 🔧 Example fixes

👉 View analysis in DeepCode’s Dashboard | Configure the bot

Things like body-parser can break proxying anything with a body. This
checks for that (req.body will become an Object) and streams the body
into the proxy request.

Fixes chimurai#90, chimurai#320, chimurai#417 - and maybe some more
It is possible that the content length is not equivalent due to JSON
serialization, so we need to re-write the Content-Length header to the
upstream.

This commit also restricts the fix to ONLY handle JSON. Other content
types could be handled with some conditionals if necessary.
@sarumont
Copy link
Copy Markdown
Author

@chimurai Sorry, lost track of this PR between work and a new baby arriving. :) I just updated with a fix for a bug I found, and I'll drop a test in as soon as I can!

@chimurai
Copy link
Copy Markdown
Owner

fixed in #492

@chimurai chimurai closed this Apr 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Modifying the POST body in onProxyReq

3 participants