docs: note that req.body may be undefined in v2 - #752
Conversation
Document the v1 to v2 change where req.body stays undefined when no body
is parsed, instead of always being initialized to {}.
Fixes expressjs#632
kilisamemarisaaa
left a comment
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?
|
yeah my bad, empty json with content length 0 still parses to {}. i narrowed the note to the no body parsed cases, missing content length or transfer encoding, or a type that doesnt match. |
Summary
req.bodystaysundefinedwhen no body is parsed, instead of always being initialized to{}.Fixes #632
Test plan