From 15569b210ef4cdf2ae60e972289b44bb9a3bae03 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 21 Aug 2026 22:12:09 -0700 Subject: [PATCH] perf(gateway): avoid single-chunk request body copy (#127783) Amp-Thread-ID: https://ampcode.com/threads/T-01a021f5-984a-7628-a30c-491c166ff247 Co-authored-by: Amp --- src/infra/http-body.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/infra/http-body.ts b/src/infra/http-body.ts index 4ab081283d38..fa3bcf67f9eb 100644 --- a/src/infra/http-body.ts +++ b/src/infra/http-body.ts @@ -434,7 +434,13 @@ export async function readRequestBodyWithLimit( const onEnd = () => { ended = true; - finish(() => resolve(Buffer.concat(chunks).toString(encoding))); + finish(() => + resolve( + chunks.length === 1 + ? chunks[0]!.toString(encoding) + : Buffer.concat(chunks).toString(encoding), + ), + ); }; const onError = (error: Error) => {