🐛 BUG: Pages `next()` headers mutable in local dev, but not in production
See original GitHub issueWhat version of Wrangler
are you using?
2.0.9
What operating system are you using?
Windows 10
Describe the Bug
The Pages Functions docs has this example:
const hello = async ({ next }) => {
const response = await next();
response.headers.set('X-Hello', 'Hello from functions Middleware!');
return response;
};
This works perfectly fine in local dev with pages dev
, but fails in production due to the next()
response having immutable headers there. This leads to frequent frustration for folks since there’s no way to get function error logs to debug this inconsistency.
To make this work in prod, you have to do something like this:
const hello = async ({ next }) => {
const rawResponse = await next();
const response = new Response(rawResponse.body, rawResponse); // clone response to create mutable headers
response.headers.set('X-Hello', 'Hello from functions Middleware!');
return response;
};
Related: https://github.com/cloudflare/cloudflare-docs/pull/4773
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Fetch Response Headers Mutable in Miniflare, not on ... - GitHub
Hey all, been working on a framework for building cloudflare workers to serve static sites. In the development process I stumbled across a ......
Read more >Dart: HTTP headers are not mutable - Stack Overflow
Basically, when you get an "HTTP headers not mutable" error, it means that you are trying to modify the headers after writing to...
Read more >Advanced Features: Security Headers - Next.js
This header controls DNS prefetching, allowing browsers to proactively perform domain name resolution on external links, images, CSS, JavaScript, and more. This ...
Read more >Safari Technology Preview Release Notes - Apple Developer
Note: Shared Tab Groups and syncing for Tab Groups, Website Settings, and Web Extensions are not enabled in this release. WebAssembly. Fixed error...
Read more >Communicating with backend services using HTTP - Angular
Most front-end applications need to communicate with a server over the HTTP protocol, to download or upload data and access other back-end services....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The change in #1325 appears to work great, thanks very much! I ran the following:
and was able to see the
x-test
header when using the new wrangler version both in prod and dev, vs an exception in prod when using the current release version, as expected. Woot! 🎉@Cherry It’s now out in
wrangler@2.0.15
🎉