Skip to content
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

fix: request overrider checks req.headers to parse body as json #1157

Merged
merged 2 commits into from Jul 2, 2018
Merged

fix: request overrider checks req.headers to parse body as json #1157

merged 2 commits into from Jul 2, 2018

Conversation

ArTiSTiX
Copy link
Contributor

fixes #1156

Request overrider was using headers from options.
But some library don't set headers via options.

Use req.headers (retreived before in the same function) to ensure body is parse as JSON when header Content-Type=application/json

@gr2m
Copy link
Member

gr2m commented Jun 29, 2018

Thanks @ArTiSTiX for the pull request. Could you please add a test?

@ArTiSTiX
Copy link
Contributor Author

ArTiSTiX commented Jul 2, 2018

@gr2m done.

I updated the old test (which was giving a false positive due to usage of request) by using node's http package and setHeader to mutate request (the approach failing, used by some other packages like superagent).

I added a test to be sure requestBody is not parsed when Content Type is not application/json.

Copy link
Member

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, thanks!

@gr2m gr2m merged commit f81fb6d into nock:master Jul 2, 2018
@lock
Copy link

lock bot commented Sep 13, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Sep 13, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants