Skip to content

Commit

Permalink
docs: handle immutable headers error (#12543)
Browse files Browse the repository at this point in the history
* docs: handle immutable headers error

* Update documentation/docs/30-advanced/20-hooks.md

Co-authored-by: Simon H <[email protected]>

---------

Co-authored-by: Tee Ming <[email protected]>
Co-authored-by: Simon H <[email protected]>
  • Loading branch information
3 people authored Jan 22, 2025
1 parent d9f1522 commit cc6dace
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions documentation/docs/30-advanced/20-hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ export async function handle({ event, resolve }) {
event.locals.user = await getUserInformation(event.cookies.get('sessionid'));

const response = await resolve(event);

// Note that modifying response headers isn't always safe.
// Response objects can have immutable headers
// (e.g. Response.redirect() returned from an endpoint).
// Modifying immutable headers throws a TypeError.
// In that case, clone the response or avoid creating a
// response object with immutable headers.
response.headers.set('x-custom-header', 'potato');

return response;
Expand Down

0 comments on commit cc6dace

Please sign in to comment.