fix(response): keep content-length header for Uint8Array responses#1504
Conversation
prepareResponse() clears event[kEventRes] before calling prepareResponseBody() to avoid duplicating the response (h3js#1259), capturing preparedHeaders from the pre-clear object. The Uint8Array branch then called event.res.headers.set("content-length", ...), which lazily recreated a brand new H3EventResponse post-clear that nothing reads — the header was silently dropped, and event[kEventRes] was left repopulated, undermining the h3js#1259 anti-duplication fix for this branch. content-length is now returned on prepareResponseBody's own result so the existing header-merge logic in prepareResponse picks it up, and event.res is no longer touched (so it stays cleared). Split out of h3js#1503 per maintainer feedback (one PR per issue). Addresses the second bug in h3js#1477; the sync-throw bug is handled separately in fix/response-prepare-error-handling. Co-Authored-By: Claude Sonnet 5 <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Uint8Array response path now returns ChangesResponse header preservation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…y-content-length # Conflicts: # test/bench/bundle.test.ts
Part of #1477 (2 of 2 — split per @pi0's request; companion to #1503).
prepareResponseclearsevent[kEventRes]beforeprepareResponseBodyruns (capturing prepared headers pre-clear to avoid duplication, #1259). TheUint8Arraybranch then setcontent-lengthviaevent.res.headers.set(...), which lazily recreated a newH3EventResponsethat nothing reads — so the header was dropped andevent.resgot repopulated. This returns the header on theprepareResponseBodyresult instead, so it is actually applied andevent.resstays cleared.Test (
middleware.test.ts,describeMatrix): aUint8Arrayresponse keeps itscontent-lengthand does not duplicate headers when passed through a secondtoResponse()pass.pnpm testis green.Drafted with AI assistance; reviewed and verified against the test suite by me.
Summary by CodeRabbit
content-lengthis preserved.Set-Cookieheaders remain intact without duplication.