-
-
Notifications
You must be signed in to change notification settings - Fork 130
#185 ALB/ELB set cookies when multiValueHeaders is not set #186
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,14 @@ | |
|
|
||
|
|
||
| def get_mock_aws_alb_event( | ||
| method, path, multi_value_query_parameters, body, body_base64_encoded | ||
| method, | ||
| path, | ||
| multi_value_query_parameters, | ||
| body, | ||
| body_base64_encoded, | ||
| multi_value_headers=True, | ||
| ): | ||
| return { | ||
| event = { | ||
| "requestContext": { | ||
| "elb": { | ||
| "targetGroupArn": "arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/lambda-279XGJDqGZ5rsrHC2Fjr/49e9d65c45c6791a" # noqa: E501 | ||
|
|
@@ -38,6 +43,10 @@ def get_mock_aws_alb_event( | |
| "body": body, | ||
| "isBase64Encoded": body_base64_encoded, | ||
| } | ||
| if multi_value_headers: | ||
| event["multiValueHeaders"] = {} | ||
|
|
||
| return event | ||
|
|
||
|
|
||
| def test_aws_alb_basic(): | ||
|
|
@@ -226,7 +235,7 @@ def test_aws_alb_scope_real( | |
| assert handler.body == b"" | ||
|
|
||
|
|
||
| def test_aws_alb_set_cookies() -> None: | ||
| def test_aws_alb_set_cookies_multiValueHeaders() -> None: | ||
| async def app(scope, receive, send): | ||
| await send( | ||
| { | ||
|
|
@@ -255,6 +264,39 @@ async def app(scope, receive, send): | |
| } | ||
|
|
||
|
|
||
| def test_aws_alb_set_cookies_headers() -> None: | ||
| async def app(scope, receive, send): | ||
| await send( | ||
| { | ||
| "type": "http.response.start", | ||
| "status": 200, | ||
| "headers": [ | ||
| [b"content-type", b"text/plain; charset=utf-8"], | ||
| [b"set-cookie", b"cookie1=cookie1; Secure"], | ||
| [b"set-cookie", b"cookie2=cookie2; Secure"], | ||
| ], | ||
| } | ||
| ) | ||
| await send({"type": "http.response.body", "body": b"Hello, world!"}) | ||
|
|
||
| handler = Mangum(app, lifespan="off") | ||
| event = get_mock_aws_alb_event( | ||
| "GET", "/test", {}, None, False, multi_value_headers=False | ||
| ) | ||
| response = handler(event, {}) | ||
| assert response == { | ||
| "statusCode": 200, | ||
| "isBase64Encoded": False, | ||
| "headers": { | ||
| "content-type": "text/plain; charset=utf-8", | ||
| "set-cookie": "cookie1=cookie1; Secure", | ||
| "Set-cookie": "cookie2=cookie2; Secure", | ||
| }, | ||
| "multiValueHeaders": {}, | ||
|
Comment on lines
+290
to
+295
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only one of headers and multiValueHeaders should be specified
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The documentation you linked makes it sound like all headers should be in multiValueHeaders, even those with a single value, if it is enabled. I'm not sure if 0.11.0 did this or did what the current "main" branch does and only send the headers that have multiple values in multiValueHeaders. I think using one or the other may be the way to go, it's a bit easier to understand what is going on, and is how the ALB documentation reads online. Let us know what AWS says if anything. |
||
| "body": "Hello, world!", | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "method,content_type,raw_res_body,res_body,res_base64_encoded", | ||
| [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again this specifies headers and multiValueHeaders