-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I overwrite a response header? #1415
Comments
Here's my read of the situation: It looks like having multiple headers of the same name is acceptable/something you might use, if the headers values can be combined into a comma-separated list. So with that in mind probably |
@MaxGabriel No, I want to have only one value. 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. |
If you don't want to restructure your code at the Yesod level (which is what I believe @MaxGabriel was suggesting), could you perhaps process your authentication token in WAI middleware instead of Yesod middleware? You would have access to all request headers, and complete control over the response headers. |
Just wondering if there is any reason why there is no |
I ended up manually creating a
|
@psibi AFAIK there is no reason why such a function couldn't exist. I had a quick look before I posted my first answer, and I think it would involve digging fairly deep. It looks as if you'd need some sort of extra encoding in |
@paul-rouse Thanks for looking up. I will open a new issue to track it (and possibly implement it once I get some spare time). I looked on other frameworks and they do seem to give the ability to replace headers [0][1][2], so I think this would be a reasonable thing to add to Yesod also. [0] https://docs.djangoproject.com/en/1.11/ref/request-response/#setting-header-fields |
CC: @paul-rouse I have implemented the relevant functionality in this PR: #1417 |
How can I overwrite previously set response header? 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:I get
but I want to get just
The text was updated successfully, but these errors were encountered: