"For example, a Content-Length header field is normally sent in a POST request even when the value is 0
(indicating an empty payload body)."
I experienced this issue using the Guzzle PHP framework which sends a "Content-Length: 0" header even when _POST_ing without a body but it has also been reported with jQuery clients.
I have also found that cURL makes the same assumption. For example:
This will cause cURL to add a Content-Length: 0 header and ultimately trigger an HTTP 400 response.
The issue has also been discussed on the type-is project where @jonathanong mentioned that parsers will need to check if the body is empty. (which is what this PR implements)
Additionally, express' body-parser package has also addressed this issue by always returning an empty object.
I personally believe that returning null is more appropriate since it makes no assumptions on the client, i.e.: why not return an empty array? or an empty string with double-quotes? all are equally valid JSON.
This PR fixes an issue where a POST request with a header of
Content-Length: 0
and no body will return an HTTP 400 error.According to RFC2730 Section 3.3.2:
I experienced this issue using the Guzzle PHP framework which sends a "Content-Length: 0" header even when _POST_ing without a body but it has also been reported with jQuery clients.
I have also found that cURL makes the same assumption. For example:
This will cause cURL to add a
Content-Length: 0
header and ultimately trigger an HTTP 400 response.The issue has also been discussed on the type-is project where @jonathanong mentioned that parsers will need to check if the body is empty. (which is what this PR implements)
Additionally, express' body-parser package has also addressed this issue by always returning an empty object.
I personally believe that returning
null
is more appropriate since it makes no assumptions on the client, i.e.: why not return an empty array? or an empty string with double-quotes? all are equally valid JSON.