Skip to content

fix(cloudflare): No body for 101, 204, 205, or 304 status codes #683

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

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/open-next/src/overrides/wrappers/cloudflare-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import type { Wrapper, WrapperHandler } from "types/overrides";

import { Writable } from "node:stream";

// Response with null body status (101, 204, 205, or 304) cannot have a body.
const NULL_BODY_STATUSES = new Set([101, 204, 205, 304]);

const handler: WrapperHandler<InternalEvent, InternalResult> =
async (handler, converter) =>
async (
Expand Down Expand Up @@ -55,7 +58,8 @@ const handler: WrapperHandler<InternalEvent, InternalResult> =
controller.enqueue(Uint8Array.from(chunk.chunk ?? chunk));
},
});
const response = new Response(readable, {
const body = NULL_BODY_STATUSES.has(statusCode) ? null : readable;
const response = new Response(body, {
status: statusCode,
headers: responseHeaders,
});
Expand Down
Loading