From 073d0f8fba8ee2564860e955a8b3a992dfd6a9fa Mon Sep 17 00:00:00 2001 From: araki <50347271+araki-yzrh@users.noreply.github.com> Date: Fri, 25 Dec 2020 15:10:40 +0900 Subject: [PATCH] Fix: APIGW v2 Request Cookie Header (#153) * fix apigw v2 request cookie header * add v1 cookie header test --- mangum/adapter.py | 3 +++ tests/conftest.py | 1 + tests/test_http.py | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/mangum/adapter.py b/mangum/adapter.py index 5876ce88..61fb4293 100644 --- a/mangum/adapter.py +++ b/mangum/adapter.py @@ -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) diff --git a/tests/conftest.py b/tests/conftest.py index 2a464295..3584c952 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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", diff --git a/tests/test_http.py b/tests/test_http.py index 535e9402..5f27d197 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -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", @@ -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"], @@ -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", @@ -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"], @@ -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",