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.
This commit is contained in:
parent
f31652c27d
commit
ad71044e6d
|
|
@ -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<number> = new Set([101, 204, 205, 304]);
|
||||
const NULL_BODY_STATUSES: ReadonlySet<number> = 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,
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue