mirror of
https://github.com/oven-sh/bun
synced 2026-02-18 14:51:52 +00:00
## Summary - When `http.ClientRequest.write()` was called more than once (streaming data in chunks), Bun was stripping the explicitly-set `Content-Length` header and switching to `Transfer-Encoding: chunked`. Node.js preserves `Content-Length` in all cases when it's explicitly set by the user. - This caused real-world failures (e.g. Vercel CLI file uploads) where large binary files streamed via multiple `write()` calls had their Content-Length stripped, causing server-side "invalid file size" errors. - The fix preserves the user's explicit `Content-Length` for streaming request bodies and skips chunked transfer encoding framing when `Content-Length` is set. Closes #27061 Closes #26976 ## Changes - **`src/http.zig`**: When a streaming request body has an explicit `Content-Length` header set by the user, use that instead of adding `Transfer-Encoding: chunked`. Added `is_streaming_request_body_with_content_length` flag to track this. - **`src/bun.js/webcore/fetch/FetchTasklet.zig`**: Skip chunked transfer encoding framing (`writeRequestData`) and the chunked terminator (`writeEndRequest`) when the request has an explicit `Content-Length`. - **`test/regression/issue/27061.test.ts`**: Regression test covering multiple write patterns (2x write, write+end(data), 3x write) plus validation that chunked encoding is still used when no `Content-Length` is set. ## Test plan - [x] New regression test passes with `bun bd test test/regression/issue/27061.test.ts` - [x] Test fails with `USE_SYSTEM_BUN=1` (confirms the bug exists in current release) - [x] Existing `test/js/node/http/` tests pass (no regressions) - [x] Fetch file upload tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com>