Skip to content

Commit 84579c1

Browse files
authored
fix: better headers.getAll polyfill (#1801)
1 parent e6b1010 commit 84579c1

File tree

1 file changed

+11
-16
lines changed
  • packages/runtime/src/helpers

1 file changed

+11
-16
lines changed

packages/runtime/src/helpers/edge.ts

+11-16
Original file line numberDiff line numberDiff line change
@@ -89,23 +89,18 @@ 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-
}
92+
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
93+
if(!('getAll' in Headers.prototype)) {
94+
Headers.prototype.getAll = function getAll(name) {
95+
name = name.toLowerCase();
96+
if (name !== "set-cookie") {
97+
throw new Error("Headers.getAll is only supported for Set-Cookie");
98+
}
99+
return [...this.entries()]
100+
.filter(([key]) => key === name)
101+
.map(([, value]) => value);
102+
};
106103
}
107-
108-
109104
// Next uses blob: urls to refer to local assets, so we need to intercept these
110105
const _fetch = globalThis.fetch
111106
const fetch = async (url, init) => {

0 commit comments

Comments
 (0)