Overwrite response header in Yesod
How can I overwrite a previously set response header in Yesod? When I use the function addHeader
, it adds another header with the same name instead of overwriting it. For example, if inside a handler function, I do this:
addHeader "foo" "bar"
addHeader "foo" "baz"
I get
foo: bar
foo: baz
but I only want to get
foo: baz
In my case, the header is an authentication token, and it works in such a way that if it is present in the request, I send it back in the response. I have implemented this as middleware. However, if it is a login request, a new token is generated and should be sent instead of the value from the request header.
source to share
addHeader
implementation of Writer.
https://www.stackage.org/haddock/lts-8.21/yesod-core-1.4.35/src/Yesod.Core.Handler.html#addHeaderInternal
Cannot be used addHeader
.
This can be achieved by hand sendWaiResponse
and Response
crafting, but it is messy.
source to share