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

Calling bodyParse.json() with empty body causes the req.body to be replaced with an empty object #123

Closed
yarandoo opened this issue Sep 10, 2015 · 1 comment
Assignees
Labels

Comments

@yarandoo
Copy link

I am invoking a GET endpoint with the following headers and an empty body:

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Cache-Control:max-age=0
Connection:keep-alive
Host:localhost:3001
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36

I have defined the bodyparse.json() middleware, and after it, the body.req gets changed from null to an empty object...Why is body-parser replacing the request object, if the content type is not json? Shouldnt the bodyparse not do anything at all given is not the appropiate content type?

Is this a deffect, or is as designed?

Thanks.

@dougwilson dougwilson self-assigned this Sep 11, 2015
@dougwilson
Copy link
Contributor

Hi! Yes, the behavior you describe is by design, for better or for worse. The behavior has been changed, to be inline with what you expect, in the 2.0 branch (https://github.com/expressjs/body-parser/tree/2.x). You will have to wait for the 2.0 release (subscribe to PR #66 for updates), just add the following to your package.json: "body-parser": "expressjs/body-parser#2.x", or work-around this (you can use the type-is module's hasBody method to detect if there was really a body or not).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants