Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/server/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 4 additions & 1 deletion tests/server-images.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading