-
-
Notifications
You must be signed in to change notification settings - Fork 82
fix: corsify issue "can't modify immutable headers" #252
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
base: v5.x
Are you sure you want to change the base?
Conversation
I can open a new issue if needed, please let me know 👍 |
Thanks @nicolasvienot - can you give me minimal repro steps to see this immutable headers issue on a Worker? I use CORS on virtually all my Workers (which is what I exclusively develop on these days) and am not running into this... I'd like to ensure this is absolutely necessary before adding so many bytes! :) |
@kwhitley I think you can use this sample to reproduce the issue:
When you access the first time, it returns 200, but the next requests will return 500 error.
And there will be a warning message in worker logs:
|
Hi @kwhitley! If it helps, I'm running into the same issue, and this fix indeed helps fix it :) |
Is this already implemented? |
@kwhitley this is still an issue; also see this thread from the Cloudflare forum explaining why you can't set headers on a cloned response: https://community.cloudflare.com/t/whats-the-point-of-response-clone/216456 |
Although I think I see why you might not be experiencing it - there's a segment of code that doesn't add the header if it's already there. So if you cached the answer post-cors (for example by adding your cache as a middleware) it might work; in the OP the cache is performed within the handler, so the response object is not longer mutable. |
Description
A fix was implemented in 74f63ab to clone the response in
corsify
in order to avoid this error:Unfortunately, it seems not to be enough, and we're still having the issue with Cloudflare when a response is modified by
corsify
. A solution we found and implemented is to recreate a response by usingnew Response(...)
.Applying the fix here.
Related Issue
Link to the related issue: related to #242
Type of Change (select one and follow subtasks)