Michał Perłakowski
Michał Perłakowski

Reputation: 92561

Overwrite response header in Yesod

How can I overwrite previously set response header in Yesod? When I use the addHeader function, 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 want to get just

foo: baz

In my case, the header is an authentication token, and it works in a way that if it's present in the request, then I send it back in the response. I implemented this as a middleware. However, if it's a login request, a new token is generated, and it should be sent instead of the value from the request header.

Upvotes: 3

Views: 230

Answers (1)

ncaq
ncaq

Reputation: 233

addHeader implementation by Writer. https://www.stackage.org/haddock/lts-8.21/yesod-core-1.4.35/src/Yesod.Core.Handler.html#addHeaderInternal

It's not possible using addHeader.

It can be achieved by using sendWaiResponse and creating Response by hand, but it's messy.

Upvotes: 1

Related Questions