From f2f62214952bd7a9f7162c275c1d4fd05937633e Mon Sep 17 00:00:00 2001 From: Greg Brimble Date: Wed, 7 Sep 2022 15:43:45 +0100 Subject: [PATCH] Use 'automatic' rather than 'auto' for 'encodeBody' --- packages/core/src/standards/http.ts | 10 +++++----- packages/core/test/standards/http.spec.ts | 4 ++-- packages/http-server/src/index.ts | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/core/src/standards/http.ts b/packages/core/src/standards/http.ts index bd59d92b7..81ada5cf4 100644 --- a/packages/core/src/standards/http.ts +++ b/packages/core/src/standards/http.ts @@ -474,7 +474,7 @@ export function withImmutableHeaders(req: Request): Request { } export interface ResponseInit extends BaseResponseInit { - readonly encodeBody?: "auto" | "manual"; + readonly encodeBody?: "automatic" | "manual"; readonly webSocket?: WebSocket; } @@ -507,7 +507,7 @@ export class Response< // https://developers.cloudflare.com/workers/runtime-apis/response#properties // noinspection TypeScriptFieldCanBeMadeReadonly - #encodeBody: "auto" | "manual"; + #encodeBody: "automatic" | "manual"; // noinspection TypeScriptFieldCanBeMadeReadonly #status?: number; readonly #webSocket?: WebSocket; @@ -556,8 +556,8 @@ export class Response< super(new BaseResponse(body, init)); } - encodeBody ??= "auto"; - if (encodeBody !== "auto" && encodeBody !== "manual") { + encodeBody ??= "automatic"; + if (encodeBody !== "automatic" && encodeBody !== "manual") { throw new TypeError(`encodeBody: unexpected value: ${encodeBody}`); } this.#encodeBody = encodeBody; @@ -597,7 +597,7 @@ export class Response< return clone; } - get encodeBody(): "auto" | "manual" { + get encodeBody(): "automatic" | "manual" { return this.#encodeBody; } diff --git a/packages/core/test/standards/http.spec.ts b/packages/core/test/standards/http.spec.ts index d0942b4e3..356f428fb 100644 --- a/packages/core/test/standards/http.spec.ts +++ b/packages/core/test/standards/http.spec.ts @@ -652,9 +652,9 @@ test("Response: supports non-standard properties", (t) => { t.is(res.webSocket, pair[0]); t.is(res.headers.get("X-Key"), "value"); }); -test("Response: encodeBody defaults to auto", (t) => { +test("Response: encodeBody defaults to automatic", (t) => { const res = new Response(null); - t.is(res.encodeBody, "auto"); + t.is(res.encodeBody, "automatic"); }); test("Response: requires status 101 for WebSocket response", (t) => { const pair = new WebSocketPair(); diff --git a/packages/http-server/src/index.ts b/packages/http-server/src/index.ts index 8f98bfe16..089dca093 100644 --- a/packages/http-server/src/index.ts +++ b/packages/http-server/src/index.ts @@ -193,7 +193,7 @@ export function createRequestListener( // If a Content-Encoding is set, and the user hasn't encoded the body, // we're responsible for doing so. const encoders: Transform[] = []; - if (headers["content-encoding"] && response.encodeBody === "auto") { + if (headers["content-encoding"] && response.encodeBody === "automatic") { // Content-Length will be wrong as it's for the decoded length delete headers["content-length"]; // Reverse of https://github.com/nodejs/undici/blob/48d9578f431cbbd6e74f77455ba92184f57096cf/lib/fetch/index.js#L1660 @@ -225,7 +225,7 @@ export function createRequestListener( // response, and it's HTML const liveReloadEnabled = HTTPPlugin.liveReload && - response.encodeBody === "auto" && + response.encodeBody === "automatic" && response.headers .get("content-type") ?.toLowerCase()