-
Notifications
You must be signed in to change notification settings - Fork 209
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
Miniflare is not rewriting headers correctly #64
Comments
Hey! 👋 This is a very interesting issue. Running the following code... const headers = new Headers({
foo: "bar",
fooz: "barz",
});
for (const [key, value] of headers) {
headers.delete(key);
headers.set(`x-${key}`, value);
}
console.log(Object.fromEntries(headers)); ...gives
...but gives
It's probably worth fixing this issue, but generally mutating the backing source behind an interator whilst iterating is a bad idea. I'd just recommend creating a new const headers = new Headers();
for (const [key, value] of event.request.headers) {
headers.set(`x-${key}`, value);
}
const response = new Response('', { headers });
return event.respondWith(response); |
This is because you are deleting the element from the same set you are iterating. If you pass const response = new Response('', { headers: {
foo: "bar",
fooz: "barz",
} })
for (const [key, value] of new Headers(response.headers)) {
response.headers.delete(key)
response.headers.set(`x-${key}`, value)
}
console.log(Object.fromEntries(response.headers)); Output:
|
This is an upstream issue with |
Fix here: nodejs/undici#1081 |
My fix was merged & released as part of 4.9.3 🎉 Adding a PR to raise the version requirement within miniflare. |
Hey! 👋 |
Let's say we want to use Cloudflare Workers as just a proxy and rewrite headers passed with the
x-
prefix.Current behavior
Expected behavior
The text was updated successfully, but these errors were encountered: