fix(qemu/http): avoid duplicate Content-Length for buffered bodies - #135
Open
geminixiang wants to merge 6 commits into
Open
fix(qemu/http): avoid duplicate Content-Length for buffered bodies#135geminixiang wants to merge 6 commits into
geminixiang wants to merge 6 commits into
Conversation
geminixiang
marked this pull request as draft
July 15, 2026 17:44
Keep Content-Length and Transfer-Encoding out of canonical request headers so hook rewrites and redirects cannot leave stale framing behind. Buffered and empty bodies leave framing to fetch; streams carry one trusted byte length for outbound serialization. Also reject ambiguous inbound framing and malformed chunk sizes, and cover buffered, streaming, hook, redirect, policy, and raw-wire behavior with regression tests.
geminixiang
force-pushed
the
fix/buffered-body-content-length-node-24-17
branch
from
July 15, 2026 18:17
7e8bf2d to
8ef0130
Compare
Keep this PR focused on the buffered Content-Length regression. Restore the existing request model, hook, redirect, and ingress parsing behavior while retaining the fetch-boundary header copy and focused regression test.
geminixiang
marked this pull request as ready for review
July 15, 2026 18:56
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 #134.
Problem
I found this while running
git cloneinside a Gondolin VM. On Node.js >= 24.17, guest requests with a buffered body fail with HTTP 502 through the QEMU HTTP bridge. SmallPOSTrequests andgit cloneover smart HTTP are affected, whileGETand streamed bodies still work.I traced the error to
content-length. The bridge sets it from the buffered body, then npm undici 6 appends another derived value before dispatching through Node's built-in undici Agent. Built-in undici 7.28 rejects the duplicated value ("181, 181") withinvalid content-length header. More details and the Node.js version bisection are in #134.What I changed
I pass a copy of
currentRequest.headerstofetch()and removecontent-lengthfrom that copy only for buffered bodies, so undici derives it once from the body.Streamed bodies keep their explicit length. The original
currentRequest.headersis not changed, so redirects and response hooks still receive the measured length.Verification
I verified the change on Node.js 24.18.0 with the QEMU backend:
POSTreturns HTTP 200 instead of 502.git clone --depth 1exits successfully instead of returning 502.Content-Lengthfor buffered and streamed bodies.host/test/qemu-net.test.tspass on Node.js 24.13 and 24.18.Contribution Agreement
By submitting this pull request, I confirm the following:
I understand that the entity Earendil Inc. (incorporated in the state of Delaware in 2025) needs some rights from me in order to utilize my contributions in this PR. As a contributor I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Earendil Inc. can use, modify, copy, and redistribute my contributions, under Earendil Inc.'s choice of terms.