SIGN IN SIGN UP
denoland / deno UNCLAIMED

A modern runtime for JavaScript and TypeScript.

0 0 3 Rust

fix(ext/fetch): preserve static request body length (#34546)

Preserve the known byte length when an already-buffered request body is exposed
as `req.body` and then forwarded via `fetch()`.

The buffered request-body fast path from #33844 can produce a static `InnerBody`
from bytes that Deno already has in memory. However, when that body is
materialized as a public `ReadableStream`, the known length was lost. As a
result, forwarding the body with
`fetch(url, { method: "POST", body:
req.body })` sent an unknown-length stream
and omitted `Content-Length`.

This stores the length in an internal `WeakMap` only for `ReadableStream`s
materialized from Deno's static `InnerBody`, then restores that length in
`extractBody()`. User-created `ReadableStream` bodies remain unknown-length.

## Test plan

- [x] Added a regression spec for forwarding `req.body` and asserting that the
      upstream request receives the original `Content-Length`.
- [x] Confirmed arbitrary user-created `ReadableStream` bodies remain
      unknown-length.
- [x] Benchmarked twice on Ryzen 9 7940HS Linux with `oha`.

Benchmark result:

- `req.text()` / `req.json()` / `req.arrayBuffer()` consume throughput remains
  unchanged within noise.
- Forwarding throughput improves by `+14–25%` in run 1 and `+11–25%` in run 2,
  because the known length avoids chunked framing.
Y
Yusuke Tanaka committed
5208330c0bd457713d2ee2622fa565fbac12d856
Parent: 5bb4051
Committed by GitHub <noreply@github.com> on 6/2/2026, 6:41:03 AM