Skip to content

how to add headers to a response using a plugin #3201

Answered by ardatan
JipSterk asked this question in Q&A
Discussion options

You must be logged in to vote

First, the code above forwards request headers to the response directly. Please be careful with that.

Second it doesn't work and you get Ensure you return a 'Response' or a 'NextResponse' in all branches of your handler. because the object lost its Response prototype when you use a spread like ...response so instead you can modify the headers of response object like; response.headers.set('x-my-header', 'my-header-value')

Third, please never call the request handler manually like that inside hooks because it will break the entire lifecycle of Yoga. If you want to change the headers of the response, please use onResponse hook to modify response.headers.

If you want to pass the data between …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JipSterk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants