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

Parse Cookies before sending to AWS Runtine Interface #11

Merged
merged 3 commits into from
Jul 5, 2023

Conversation

deleugpn
Copy link
Member

@deleugpn deleugpn commented Jul 5, 2023

Without parsing cookies, the attribute request.cookies is always empty

Co-authored-by: Denis Alustau <denisalustau@gmail.com>
@deleugpn deleugpn marked this pull request as draft July 5, 2023 11:52
@deleugpn
Copy link
Member Author

deleugpn commented Jul 5, 2023

This isn't ready yet. Although it fixes the issue on the ExpressJS side, the way the cookies arrive on Bref breaks at https://github.com/brefphp/bref/blob/master/src/Event/Http/HttpRequestEvent.php#L192-L195 so it's likely we're not being compatible with API Gateway V2 here. We need to find a way to send the cookies exactly like Amazon does.

Co-authored-by: Denis Alustau <denisalustau@gmail.com>
@deleugpn deleugpn marked this pull request as ready for review July 5, 2023 12:51
Copy link
Member

@mnapoli mnapoli left a comment

Choose a reason for hiding this comment

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

Any reason why no test changed? Are you able to add a test that covers the change? (maybe we need a test with a cookie value containing special characters?)

@@ -37,12 +37,14 @@ export function httpRequestToEvent(request: Request): APIGatewayProxyEventV2 {
const bodyString = request.method === 'GET' ? '' : request.body.toString('utf8');
const shouldSendBase64 = request.method === 'GET' ? false : bodyString.includes('Content-Disposition: form-data');

const cookies = request.headers.cookie ? request.headers.cookie.split('; ') : [];
Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid this might break if a cookie contains the ; character, could you add a test to cover that scenario?

Copy link
Member Author

Choose a reason for hiding this comment

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

cookies, like most things HTTP, need to be URL-encoded.

This is a cookie with ;

image

which is what makes it safe to do the split on ;.


I'm trying to understand the tests to see if I can add one

Copy link
Member

Choose a reason for hiding this comment

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

🤦 of course sorry, that makes sense!

Co-authored-by: Denis Alustau <denisalustau@gmail.com>
@deleugpn
Copy link
Member Author

deleugpn commented Jul 5, 2023

@mnapoli tests added!

@mnapoli
Copy link
Member

mnapoli commented Jul 5, 2023

Awesome thanks!

@mnapoli mnapoli merged commit fcc577c into brefphp:main Jul 5, 2023
5 checks passed
@deleugpn deleugpn deleted the parse-cookies branch July 5, 2023 14:55
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

Successfully merging this pull request may close these issues.

None yet

2 participants