fix(http2): send body for non-expectsPayload methods with content#5030
Merged
metcoder95 merged 1 commit intomainfrom Apr 15, 2026
Merged
fix(http2): send body for non-expectsPayload methods with content#5030metcoder95 merged 1 commit intomainfrom
metcoder95 merged 1 commit intomainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5030 +/- ##
==========================================
- Coverage 93.04% 93.03% -0.02%
==========================================
Files 110 110
Lines 35793 35793
==========================================
- Hits 33305 33301 -4
- Misses 2488 2492 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Previously, client-h2.js unconditionally set contentLength to null for methods that don't expect a payload (DELETE, GET, HEAD, etc.), but still passed the body to writeBodyH2. This caused writeBuffer to assert that contentLength === body.byteLength, which failed when contentLength was null. The fix changes the condition to match H1 behavior: only omit Content-Length when the body is empty (contentLength === 0) for non-expectsPayload methods. When a body is present, the Content-Length header is included and the body is sent correctly. Fixes #5027
a88b24b to
b94f09b
Compare
metcoder95
approved these changes
Apr 15, 2026
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.
Fixes #5027
Summary
HTTP/2 crashes with
AssertionError: buffer body must have content lengthwhen sending DELETE (or other non-expectsPayload methods) with a body.Root Cause
In
lib/dispatcher/client-h2.js, thewriteH2function unconditionally setcontentLength = nullfor all methods that don't expect a payload (DELETE, GET, HEAD, etc.). However, when a body was provided, it still got passed towriteBodyH2, which then calledwriteBufferwithbodyandnullcontentLength. ThewriteBufferfunction assertscontentLength === body.byteLength, which fails whencontentLengthisnull.Fix
Changed line 625 from:
to:
This matches the H1 behavior and only omits the Content-Length header when the body is empty for methods that don't expect a payload. When a body is present, the Content-Length header is included and the body is sent correctly.
Testing