Skip to content

fix: better headers.getAll polyfill #1801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 22, 2022
Merged
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
27 changes: 11 additions & 16 deletions packages/runtime/src/helpers/edge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,18 @@ globalThis.process = { env: {...Deno.env.toObject(), NEXT_RUNTIME: 'edge', 'NEXT
const self = {}
let _ENTRIES = {}

class Response extends globalThis.Response {
constructor(body, init) {
super(body, init);
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
this.headers.getAll = (name) => {
name = name.toLowerCase();
if (name !== "set-cookie") {
throw new Error("Headers.getAll is only supported for Set-Cookie");
}
return [...this.headers.entries()]
.filter(([key]) => key === name)
.map(([, value]) => value);
};
}
// Next.js uses this extension to the Headers API implemented by Cloudflare workerd
if(!('getAll' in Headers.prototype)) {
Headers.prototype.getAll = function getAll(name) {
name = name.toLowerCase();
if (name !== "set-cookie") {
throw new Error("Headers.getAll is only supported for Set-Cookie");
}
return [...this.entries()]
.filter(([key]) => key === name)
.map(([, value]) => value);
};
}


// Next uses blob: urls to refer to local assets, so we need to intercept these
const _fetch = globalThis.fetch
const fetch = async (url, init) => {
Expand Down