Skip to content

Commit 8b6e0c1

Browse files
committed
WSGI use new headers helper class
1 parent 0331e85 commit 8b6e0c1

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

aikido_zen/context/wsgi/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from .extract_wsgi_headers import extract_wsgi_headers
66
from .build_url_from_wsgi import build_url_from_wsgi
77
from ..parse_cookies import parse_cookies
8+
from ...helpers.headers import Headers
89

910

1011
@dataclass
1112
class WSGIContext:
1213
method: str
13-
headers: Dict[str, List[str]]
14+
headers: Headers
1415
cookies: dict
1516
url: str
1617
query: dict
@@ -22,7 +23,7 @@ def parse_wsgi_environ(environ) -> WSGIContext:
2223
This extracts WSGI attributes, described in :
2324
https://peps.python.org/pep-3333/#environ-variables
2425
"""
25-
headers: Dict[str, List[str]] = extract_wsgi_headers(environ)
26+
headers: Headers = extract_wsgi_headers(environ)
2627
# Content type is generally not included as a header, do include this as a header to simplify :
2728
if "CONTENT_TYPE" in environ:
2829
headers["CONTENT_TYPE"] = [environ["CONTENT_TYPE"]]

aikido_zen/context/wsgi/extract_wsgi_headers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
from typing import Dict, List
44

5+
from aikido_zen.helpers.headers import Headers
56

6-
def extract_wsgi_headers(request) -> Dict[str, List[str]]:
7+
8+
def extract_wsgi_headers(request) -> Headers:
79
"""Extracts WSGI headers which start with HTTP_ from request dict"""
8-
headers = {}
10+
headers = Headers()
911
for key, value in request.items():
1012
if key.startswith("HTTP_"):
1113
# Remove the 'HTTP_' prefix and store in the headers dictionary
12-
headers[key[5:]] = [value]
14+
header_key = key[5:]
15+
headers.store_header(header_key, value)
1316
return headers

0 commit comments

Comments
 (0)