Skip to content
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

Repeated headers are dropped during response decoding #5

Open
imalsogreg opened this issue Feb 3, 2023 · 0 comments
Open

Repeated headers are dropped during response decoding #5

imalsogreg opened this issue Feb 3, 2023 · 0 comments

Comments

@imalsogreg
Copy link
Contributor

imalsogreg commented Feb 3, 2023

wai responses with multiple headers with the same key are not preserved when converting them to an Aeson object, because the list of (HeaderName, HeaderValue) pairs goes through a hashmap while generating the response object in API Gateway's preferred format: https://github.com/deckgo/wai-lambda/blob/master/src/Network/Wai/Handler/Lambda.hs#L334

This is problematic for any header that appears multiple times, for example, Set-Cookie and Cookie headers, which are often present multiple times in a response/request.

The lambda payload format singles cookies out for special treatment, putting them in their own top-level "cookies": [] field, not in "headers":{}.

I'm not sure, but I believe the solution is to encode Cookie headers specially for wai requests (pulling them from the lambda "cookies" field and adding them to Wai request headers), and to decode Set-Cookie headers specially for wai responses (filtering Set-Cookie headers from the Wai response and placing those into "cookies" for the lambda response object). At least this is what I'm doing in my wai-lambda fork, and it appears to do the right thing (cookies are set in the browser and accepted by the server for my lambda-hosted servant app).

@imalsogreg imalsogreg mentioned this issue Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant