Skip to content

fix(http2): send body for non-expectsPayload methods with content#5030

Merged
metcoder95 merged 1 commit intomainfrom
fix/issue-5027
Apr 15, 2026
Merged

fix(http2): send body for non-expectsPayload methods with content#5030
metcoder95 merged 1 commit intomainfrom
fix/issue-5027

Conversation

@mcollina
Copy link
Copy Markdown
Member

Fixes #5027

Summary

HTTP/2 crashes with AssertionError: buffer body must have content length when sending DELETE (or other non-expectsPayload methods) with a body.

Root Cause

In lib/dispatcher/client-h2.js, the writeH2 function unconditionally set contentLength = null for all methods that don't expect a payload (DELETE, GET, HEAD, etc.). However, when a body was provided, it still got passed to writeBodyH2, which then called writeBuffer with body and null contentLength. The writeBuffer function asserts contentLength === body.byteLength, which fails when contentLength is null.

Fix

Changed line 625 from:

if (!expectsPayload) {

to:

if (contentLength === 0 && !expectsPayload) {

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

  • All existing HTTP/2 tests pass (42 tests)
  • All client and content-length tests pass (342 tests)
  • Verified the fix resolves the reported issue with DELETE + body over HTTP/2

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.03%. Comparing base (6824eed) to head (b94f09b).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regression test?

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
@metcoder95 metcoder95 merged commit bc0a19c into main Apr 15, 2026
35 checks passed
@metcoder95 metcoder95 deleted the fix/issue-5027 branch April 15, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTP/2: buffer body must have content length assertion when sending DELETE with a body

3 participants