feat(request): add req.hasBody getter#7206
Open
walle250ai wants to merge 1 commit intoexpressjs:masterfrom
Open
feat(request): add req.hasBody getter#7206walle250ai wants to merge 1 commit intoexpressjs:masterfrom
walle250ai wants to merge 1 commit intoexpressjs:masterfrom
Conversation
Returns true if request has a non-empty body based on Content-Length or Transfer-Encoding headers, without relying on external hasBody utilities that treat Content-Length:0 as truthy. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
I see two problems with this:
By the way, I did not see anybody requesting adding this functionality directly to Express. |
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 free
to 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.hasBodyboolean getter tolib/request.jstrueif request carries a non-empty body:Content-Length > 0ORTransfer-Encodingheader presentfalseforContent-Length: 0, missing content headersdefineGetterpattern (same asreq.fresh,req.xhr, etc.)Motivation
Express has no built-in way to check if a request has a body before parsing. Developers currently repeat
req.headers["content-length"]checks across middleware.req.hasBodysurfaces this as a first-class property.Test plan
mocha --require test/support/env test/req.hasBody.js🤖 Generated with Claude Code