Uh oh!
There was an error while loading. Please reload this page.
docs: note that req.body may be undefined in v2 - #752
Open
Hashim1999164 wants to merge 2 commits into
Open
Conversation
Document the v1 to v2 change where req.body stays undefined when no body
is parsed, instead of always being initialized to {}.
Fixesexpressjs#632
kilisamemarisaaa
left a comment
Contributor
There was a problem hiding this comment.
The "empty body" example is broader than v2's actual behavior. A request with a matching Content-Type: application/json and Content-Length: 0 is still considered to have a body, and the JSON parser returns {}; the existing test/json.js cases "should handle Content-Length: 0" and "should handle empty message-body" both assert that result.
The breaking change applies when no body is parsed, for example when the request has neither Content-Length nor Transfer-Encoding, or when Content-Type does not match. Could this example be narrowed so it does not imply that all zero-length JSON requests now leave req.body undefined?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
req.bodystaysundefinedwhen no body is parsed, instead of always being initialized to{}.Fixes#632
Test plan