Skip to content

Commit c5421fa

Browse files
sommeeeerconico974
andauthored
fix(edge-converter): Ensure null body status codes dont return a body (#906)
* fix(edge-converter): Ensure null body status dont return a body * changeset * Update packages/open-next/src/overrides/converters/edge.ts Co-authored-by: conico974 <[email protected]> * comment --------- Co-authored-by: conico974 <[email protected]>
1 parent f46bc00 commit c5421fa

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

.changeset/mean-crabs-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
fix(edge-converter): Ensure null body status codes dont return a body

packages/open-next/src/overrides/converters/edge.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ declare global {
1515
var __dangerous_ON_edge_converter_returns_request: boolean | undefined;
1616
}
1717

18+
// https://fetch.spec.whatwg.org/#statuses
19+
const NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);
20+
1821
const converter: Converter<InternalEvent, InternalResult | MiddlewareResult> = {
1922
convertFrom: async (event: Request) => {
2023
const url = new URL(event.url);
@@ -97,7 +100,12 @@ const converter: Converter<InternalEvent, InternalResult | MiddlewareResult> = {
97100
}
98101
}
99102

100-
return new Response(result.body as ReadableStream, {
103+
// We should not return a body for statusCode's that doesn't allow bodies
104+
const body = NULL_BODY_STATUSES.has(result.statusCode)
105+
? null
106+
: (result.body as ReadableStream);
107+
108+
return new Response(body, {
101109
status: result.statusCode,
102110
headers,
103111
});

0 commit comments

Comments
 (0)