Skip to content

Commit

Permalink
Use 'automatic' rather than 'auto' for 'encodeBody'
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble committed Sep 7, 2022
1 parent ab60cad commit f2f6221
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions packages/core/src/standards/http.ts
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -597,7 +597,7 @@ export class Response<
return clone;
}

get encodeBody(): "auto" | "manual" {
get encodeBody(): "automatic" | "manual" {
return this.#encodeBody;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/standards/http.spec.ts
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions packages/http-server/src/index.ts
Expand Up @@ -193,7 +193,7 @@ export function createRequestListener<Plugins extends HTTPPluginSignatures>(
// 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
Expand Down Expand Up @@ -225,7 +225,7 @@ export function createRequestListener<Plugins extends HTTPPluginSignatures>(
// response, and it's HTML
const liveReloadEnabled =
HTTPPlugin.liveReload &&
response.encodeBody === "auto" &&
response.encodeBody === "automatic" &&
response.headers
.get("content-type")
?.toLowerCase()
Expand Down

0 comments on commit f2f6221

Please sign in to comment.