Skip to content

Commit b400efb

Browse files
fix: polyfill headers.getAll (#1766)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 866abcb commit b400efb

File tree

1 file changed

+17
-0
lines changed
  • packages/runtime/src/helpers

1 file changed

+17
-0
lines changed

packages/runtime/src/helpers/edge.ts

+17
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ globalThis.process = { env: {...Deno.env.toObject(), NEXT_RUNTIME: 'edge', 'NEXT
8989
const self = {}
9090
let _ENTRIES = {}
9191
92+
class Response extends globalThis.Response {
93+
constructor(body, init) {
94+
super(body, init);
95+
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
96+
this.headers.getAll = (name) => {
97+
name = name.toLowerCase();
98+
if (name !== "set-cookie") {
99+
throw new Error("Headers.getAll is only supported for Set-Cookie");
100+
}
101+
return [...this.headers.entries()]
102+
.filter(([key]) => key === name)
103+
.map(([, value]) => value);
104+
};
105+
}
106+
}
107+
108+
92109
// Next uses blob: urls to refer to local assets, so we need to intercept these
93110
const _fetch = globalThis.fetch
94111
const fetch = async (url, init) => {

0 commit comments

Comments
 (0)