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

fix(aws-lambda): return outgoing cookies on response objects #357

Merged
merged 1 commit into from
Aug 24, 2022

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

resolves #245

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR returns an array of cookies to set from aws-lambda preset rather than keeping them on the headers. More info in AWS docs.

@brtinney - would be grateful if you could confirm this resolves the issue for you.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@danielroe danielroe added the bug Something isn't working label Jul 20, 2022
@danielroe danielroe requested a review from pi0 July 20, 2022 13:06
@danielroe danielroe self-assigned this Jul 20, 2022
@brtinney
Copy link

@danielroe: It appears to properly set the cookies now, although I still have to use: event.headers.cookie = event.cookies.join("; "); over event.headers.cookie = event.cookies.join(","); in order to use the cookie library to parse them from the event, as the (more common?) convention is to use ; to separate them.

That said, I'm not sure if I can necessarily insist that nitro should be using ; to separate the cookies. I can at least get away with doing parse((req.headers.cookie || '').replace(/,/g, ';')) in my actual code instead of having to modify the built mjs for that particular issue. (Which should be safe since neither , or ; are supposed to actually appear in cookies....)

Thanks!

@danielroe
Copy link
Member Author

@brtinney I think the other issue should be resolved with #356.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally hadn't a chance to test but hope change is working

@pi0 pi0 merged commit c6058e1 into main Aug 24, 2022
@pi0 pi0 deleted the fix/lamda-cookies-return branch August 24, 2022 19:58
@rhumie
Copy link

rhumie commented Sep 15, 2022

@pi0
I have tried this and it doesn't work.
I configured Amazon API Gateway proxy integration to work with an AWS Lambda function. When I call my endpoint, I receive a configuration error and an HTTP 502 status code.

Execution failed due to configuration error: Malformed Lambda proxy response

This is due to the fact that cookies are returned in the response object.
For API Gateway to handle a Lambda function's response, the function must return output according to the following JSON format. Additional fields are not allowed.

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "body": "..."
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-lambda preset should use cookies vs set-cookie header in response
4 participants