Skip to content

Commit aaf312f

Browse files
authored
fix(cloudflare): No body for 101, 204, 205, or 304 status codes (#683)
1 parent 0203823 commit aaf312f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/open-next/src/overrides/wrappers/cloudflare-node.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import type { Wrapper, WrapperHandler } from "types/overrides";
77

88
import { Writable } from "node:stream";
99

10+
// Response with null body status (101, 204, 205, or 304) cannot have a body.
11+
const NULL_BODY_STATUSES = new Set([101, 204, 205, 304]);
12+
1013
const handler: WrapperHandler<InternalEvent, InternalResult> =
1114
async (handler, converter) =>
1215
async (
@@ -55,7 +58,8 @@ const handler: WrapperHandler<InternalEvent, InternalResult> =
5558
controller.enqueue(Uint8Array.from(chunk.chunk ?? chunk));
5659
},
5760
});
58-
const response = new Response(readable, {
61+
const body = NULL_BODY_STATUSES.has(statusCode) ? null : readable;
62+
const response = new Response(body, {
5963
status: statusCode,
6064
headers: responseHeaders,
6165
});

0 commit comments

Comments
 (0)