Skip to content

Commit d5df96c

Browse files
committed
Merge branch 'mr/forestier/flask-app-add-cookies' into 'master'
Update Flask wrapper to add support of HTTP_COOKIE See merge request it/e3-aws!57
2 parents 0b11726 + 0259758 commit d5df96c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/e3/aws/troposphere/awslambda/flask_apigateway_wrapper.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ def create_flask_wsgi_environ(self, event: dict, context: dict) -> dict:
138138
# Normalized headers
139139
headers = {k.title(): v for k, v in event["headers"].items()}
140140

141+
# Normalized cookies
142+
cookies = ";".join(c for c in event.get("cookies", []))
143+
141144
# Body
142145
body = event.get("body", "")
143146
if event.get("isBase64Encoded", "false") == "true":
@@ -177,6 +180,10 @@ def create_flask_wsgi_environ(self, event: dict, context: dict) -> dict:
177180
wsgi_name = "HTTP_" + header.upper().replace("-", "_")
178181
environ[wsgi_name] = headers[header]
179182

183+
# Set HTTP_COOKIE if necessary
184+
if cookies:
185+
environ["HTTP_COOKIE"] = cookies
186+
180187
# Set REMOTE_USER if necessary
181188
if remote_user:
182189
environ["REMOTE_USER"] = remote_user

tests/tests_e3_aws/troposphere/awslambda/source_dir/http_api_wsgi_flask_environment.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"HTTP_ACCEPT_ENCODING": "gzip, deflate, br",
2121
"HTTP_ACCEPT_LANGUAGE": "en-US,en;q=0.9",
2222
"HTTP_CONTENT_LENGTH": "0",
23+
"HTTP_COOKIE": "s_fid=7AABXMPL1AFD9BBF-0643XMPL09956DE2;regStatus=pre-register",
2324
"HTTP_SEC_FETCH_DEST": "document",
2425
"HTTP_SEC_FETCH_MODE": "navigate",
2526
"HTTP_SEC_FETCH_SITE": "cross-site",

0 commit comments

Comments
 (0)