Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mean-crabs-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/aws": patch
---

fix(edge-converter): Ensure null body status codes dont return a body
10 changes: 9 additions & 1 deletion packages/open-next/src/overrides/converters/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ declare global {
var __dangerous_ON_edge_converter_returns_request: boolean | undefined;
}

// https://fetch.spec.whatwg.org/#statuses
const NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);

const converter: Converter<InternalEvent, InternalResult | MiddlewareResult> = {
convertFrom: async (event: Request) => {
const url = new URL(event.url);
Expand Down Expand Up @@ -97,7 +100,12 @@ const converter: Converter<InternalEvent, InternalResult | MiddlewareResult> = {
}
}

return new Response(result.body as ReadableStream, {
// We should not return a body for statusCode's that doesn't allow bodies
const body = NULL_BODY_STATUSES.has(result.statusCode)
? null
: (result.body as ReadableStream);

return new Response(body, {
status: result.statusCode,
headers,
});
Expand Down
Loading