Skip to content

Commit

Permalink
fix(cloudflare): No body for 101, 204, 205, or 304 status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Dec 20, 2024
1 parent 0203823 commit e4bd1bb
Showing 1 changed file with 5 additions and 1 deletion.
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

0 comments on commit e4bd1bb

Please sign in to comment.