set cookie and redirect: Can't modify immutable headers.

I'm trying to set a session cookie and redirect with a 302 but appending the headers throws this exception: Can't modify immutable headers. TypeError: Can't modify immutable headers. let res = Response.redirect(url.origin+"/my/",302); res.headers.append("Set-Cookie", "sid=" + user.sid + "; Path=/; Secure; Max-Age=32000000; HttpOnly");
3 Replies
Paolo of Lost Pages
I "resolved" avoiding the problem by using an HTML meta redirect :/
Erisa
Erisa7mo ago
You need to clone the response object before modifying it https://developers.cloudflare.com/workers/examples/alter-headers/
// Clone the response so that it's no longer immutable
const newResponse = new Response(response.body, response);
// Clone the response so that it's no longer immutable
const newResponse = new Response(response.body, response);
Paolo of Lost Pages
Thank you!
Want results from more Discord servers?
Add your server