Skip to content

Commit

Permalink
Fix: APIGW v2 Request Cookie Header (Kludex#153)
Browse files Browse the repository at this point in the history
* fix apigw v2 request cookie header

* add v1 cookie header test
  • Loading branch information
araki-yzrh authored and four43 committed Mar 27, 2021
1 parent 9750ee6 commit 073d0f8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mangum/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def __call__(self, event: dict, context: dict) -> dict:
else {}
)

if "cookies" in event:
headers["cookie"] = "; ".join(event.get("cookies", []))

server_name = headers.get("host", "mangum")
if ":" not in server_name:
server_port = headers.get("x-forwarded-port", 80)
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def mock_http_event(request):
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Cookie": "cookie1; cookie2",
"Host": "test.execute-api.us-west-2.amazonaws.com",
"Upgrade-Insecure-Requests": "1",
"X-Forwarded-For": "192.168.100.1, 192.168.1.1",
Expand Down
5 changes: 5 additions & 0 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async def app(scope, receive, send):
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Cookie": "cookie1; cookie2",
"Host": "test.execute-api.us-west-2.amazonaws.com",
"Upgrade-Insecure-Requests": "1",
"X-Forwarded-For": "192.168.100.1, 192.168.1.1",
Expand Down Expand Up @@ -104,6 +105,7 @@ async def app(scope, receive, send):
[b"cloudfront-is-smarttv-viewer", b"false"],
[b"cloudfront-is-tablet-viewer", b"false"],
[b"cloudfront-viewer-country", b"US"],
[b"cookie", b"cookie1; cookie2"],
[b"host", b"test.execute-api.us-west-2.amazonaws.com"],
[b"upgrade-insecure-requests", b"1"],
[b"x-forwarded-for", b"192.168.100.1, 192.168.1.1"],
Expand Down Expand Up @@ -160,6 +162,7 @@ async def app(scope, receive, send):
"CloudFront-Is-SmartTV-Viewer": "false",
"CloudFront-Is-Tablet-Viewer": "false",
"CloudFront-Viewer-Country": "US",
"Cookie": "cookie1; cookie2",
"Host": "test.execute-api.us-west-2.amazonaws.com",
"Upgrade-Insecure-Requests": "1",
"X-Forwarded-For": "192.168.100.1, 192.168.1.1",
Expand Down Expand Up @@ -220,6 +223,7 @@ async def app(scope, receive, send):
[b"cloudfront-is-smarttv-viewer", b"false"],
[b"cloudfront-is-tablet-viewer", b"false"],
[b"cloudfront-viewer-country", b"US"],
[b"cookie", b"cookie1; cookie2"],
[b"host", b"test.execute-api.us-west-2.amazonaws.com"],
[b"upgrade-insecure-requests", b"1"],
[b"x-forwarded-for", b"192.168.100.1, 192.168.1.1"],
Expand Down Expand Up @@ -603,6 +607,7 @@ async def app(scope, receive, send):
[b"x-forwarded-port", b"443"],
[b"x-forwarded-proto", b"https"],
[b"host", b"test.execute-api.us-west-2.amazonaws.com"],
[b"cookie", b"cookie1; cookie2"],
],
"http_version": "1.1",
"method": "GET",
Expand Down

0 comments on commit 073d0f8

Please sign in to comment.