From 9b44acc8c428d98e000a22355b2d0b939729d6b6 Mon Sep 17 00:00:00 2001 From: luvs01 <27862058+luvs01@users.noreply.github.com> Date: Mon, 10 Aug 2026 09:39:30 +0900 Subject: [PATCH] fix(images): ignore size headers on bodyless responses --- src/server/images.ts | 3 +++ tests/server-images.test.ts | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/server/images.ts b/src/server/images.ts index edc710933..c3ee1f464 100644 --- a/src/server/images.ts +++ b/src/server/images.ts @@ -84,6 +84,9 @@ export async function readImageResponseBytes( cancelUnlockedResponseBody(response, signal.reason); throw signal.reason; } + if (response.body === null) { + return { bytes: new Uint8Array(0), oversized: false }; + } const maxBytes = options.maxBytes ?? IMAGES_RESPONSE_MAX_BYTES; const contentLength = response.headers.get("content-length"); diff --git a/tests/server-images.test.ts b/tests/server-images.test.ts index 86e09624f..d286c192f 100644 --- a/tests/server-images.test.ts +++ b/tests/server-images.test.ts @@ -783,7 +783,10 @@ test("relays a bodyless upstream image status without synthesizing a body", asyn globalThis.fetch = (async (input: RequestInfo | URL, init?: RequestInit) => { const requestUrl = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url; if (new URL(requestUrl).hostname === "chatgpt.com") { - return new Response(null, { status: 204 }); + return new Response(null, { + status: 204, + headers: { "content-length": String(IMAGES_RESPONSE_MAX_BYTES + 1) }, + }); } return originalFetch(input, init); }) as typeof fetch;