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

requestBody is not parsed as JSON when replying #1156

Closed
ArTiSTiX opened this issue Jun 29, 2018 · 1 comment
Closed

requestBody is not parsed as JSON when replying #1156

ArTiSTiX opened this issue Jun 29, 2018 · 1 comment

Comments

@ArTiSTiX
Copy link
Contributor

When filtering/matching body (for a POST request), nock correctly parses it as JSON, but once the route matched, the reply function does not receive a parsed requestBody, but string representation only.

This is due to RequestOverrider not taking real request headers into account (using options.headers instead of req.headers). Some library (i'm using superagent), or usage of those, does not define headers in options, but mutates request with setHeader() before playing it.

Could we change options.headers to req.headers ?

req.headers = req.getHeaders ? req.getHeaders() : req._headers;

if (requestBody && common.isJSONContent(options.headers)) {

@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

No branches or pull requests

1 participant