From ad71044e6d1d64954f8ae9ba98588a12407815e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A6=A8=E5=86=89?= Date: Thu, 10 Sep 2026 10:45:25 +0800 Subject: [PATCH] refactor(plugin-sdk): drop unrepresentable 101 from null-body set Greptile: the Response constructor rejects status 101 by range, so listing it in NULL_BODY_STATUSES suggested support the shim cannot provide. Keep the set to 204/205/304 and explain the 101 exclusion in the comment. --- packages/plugins/sdk/src/worker-rpc-host.ts | 17 +++++++++-------- .../plugins/sdk/tests/worker-rpc-host.test.ts | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/plugins/sdk/src/worker-rpc-host.ts b/packages/plugins/sdk/src/worker-rpc-host.ts index 912d419211..e9fd35ce38 100644 --- a/packages/plugins/sdk/src/worker-rpc-host.ts +++ b/packages/plugins/sdk/src/worker-rpc-host.ts @@ -242,11 +242,12 @@ function canonicalize(value: unknown): string { } /** - * Statuses the Fetch spec defines as null-body. The `Response` constructor - * throws "Invalid response status code" when one of them carries a body, so - * the http.fetch shim must rebuild them with an explicit `null` body. + * Null-body statuses the `Response` constructor can represent (the Fetch + * spec also defines 101, but the constructor rejects it by status range). + * The constructor throws "Invalid response status code" when one of these + * carries a body, so the http.fetch shim rebuilds them with `null` instead. */ -const NULL_BODY_STATUSES: ReadonlySet = new Set([101, 204, 205, 304]); +const NULL_BODY_STATUSES: ReadonlySet = new Set([204, 205, 304]); export function isWorkerEntrypoint(entry: string, moduleUrl: string): boolean { const thisFile = realpathOrResolvedPath(fileURLToPath(moduleUrl)); @@ -617,10 +618,10 @@ export function startWorkerRpcHost(options: WorkerRpcHostOptions): WorkerRpcHost }); // Reconstruct a Response-like object from the serialized result. - // The Fetch spec forbids a body on null-body statuses (101, 204, - // 205, 304), so `new Response("")` would throw for a successful - // 204 No Content and the plugin would report a landed write as - // failed. Pass `null` for those statuses, matching global fetch. + // The Fetch spec forbids a body on null-body statuses, so + // `new Response("")` would throw for a successful 204 No Content + // and the plugin would report a landed write as failed. Pass + // `null` for those statuses, matching global fetch. return new Response(NULL_BODY_STATUSES.has(result.status) ? null : result.body ?? null, { status: result.status, statusText: result.statusText, diff --git a/packages/plugins/sdk/tests/worker-rpc-host.test.ts b/packages/plugins/sdk/tests/worker-rpc-host.test.ts index dc5308fca3..00e2726830 100644 --- a/packages/plugins/sdk/tests/worker-rpc-host.test.ts +++ b/packages/plugins/sdk/tests/worker-rpc-host.test.ts @@ -1102,8 +1102,8 @@ describe("worker duplex channel dispatch", () => { describe("worker http.fetch response rebuild", () => { // The host serializes the upstream reply as // `{ status, statusText, headers, body }`. The worker rebuilds a `Response` - // from those fields. The Fetch spec forbids a body on null-body statuses - // (101, 204, 205, 304), so a plain `new Response(body)` throws for a + // from those fields. The Fetch spec forbids a body on null-body + // statuses (204, 205, 304), so a plain `new Response(body)` throws for a // successful 204 No Content and the plugin reports a landed write as failed. // The shim must drop the serialized body for those statuses, matching what // global `fetch` returns for the same upstream reply.