perf(http): read a declared-length fetch body with arrayBuffer()
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 20s
CI / build (pull_request) Successful in 29s
CI / runtimes (edge) (pull_request) Successful in 23s
CI / runtimes (deno) (pull_request) Successful in 32s

The chunked reader added for the incremental 413 (4d1639f) cut a Bun JSON
POST by more than half: 37.6k -> 11.7k req/s on jarvis. A well-formed
Content-Length inside the limit already bounds the body, because the
runtime frames it by that header, so arrayBuffer() is safe there and native
in Bun, Deno and workerd. byteLength is still checked for a Request built in
user code whose header and body disagree. Chunked uploads keep the bounded
read.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
chrnx committed 2026-10-27 22:35:06 -05:00
1 parent 5b2143fcb7
commit 133af8dfe5
3 files changed
+31

No files matched your search

+8
View File
@@ -284,6 +284,14 @@ describe('app.fetch bounded body reads (#105)', () => {
expect(await res.json()).toEqual({ length: 1_500_000 });
});
it('a declared content-length under the limit does not let a longer body through', async () => {
const body = countingStream(1, 20);
const res = await limitsApp.fetch(post('/limits/small', body.stream, { 'content-length': '5' }));
expect(res.status).toBe(413);
});
it('a malformed content-length is ignored, and the stream count enforces the limit', async () => {
const body = countingStream(1, 20);