Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'automatic' rather than 'auto' for 'encodeBody' #358

Merged
merged 1 commit into from Sep 7, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/core/src/standards/http.ts
Expand Up @@ -489,7 +489,7 @@ export function withImmutableHeaders<Body extends Request | Response>(
}

export interface ResponseInit extends BaseResponseInit {
readonly encodeBody?: "auto" | "manual";
readonly encodeBody?: "automatic" | "manual";
readonly webSocket?: WebSocket;
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/standards/http.spec.ts
Expand Up @@ -695,7 +695,7 @@ test("Response: supports non-standard properties", (t) => {
});
test("Response: encodeBody defaults to auto", (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 @@ -176,7 +176,7 @@ async function writeResponse(
// 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") {
// Reverse of https://github.com/nodejs/undici/blob/48d9578f431cbbd6e74f77455ba92184f57096cf/lib/fetch/index.js#L1660
const codings = headers["content-encoding"]
.toString()
Expand Down Expand Up @@ -207,7 +207,7 @@ async function writeResponse(
// response, and it's HTML
const liveReloadEnabled =
liveReload &&
response.encodeBody === "auto" &&
response.encodeBody === "automatic" &&
response.headers.get("content-type")?.toLowerCase().includes("text/html");

// If Content-Length is specified, and we're live-reloading, we'll
Expand Down