File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,20 @@ class HTTPRequest:
40
40
"""HTTP version, e.g. "HTTP/1.1"."""
41
41
42
42
headers : Dict [str , str ]
43
- """Headers from the request."""
43
+ """
44
+ Headers from the request as `dict`.
45
+
46
+ Values should be accessed using **lower case header names**.
47
+
48
+ Example::
49
+
50
+ request.headers
51
+ # {'connection': 'keep-alive', 'content-length': '64' ...}
52
+ request.headers["content-length"]
53
+ # '64'
54
+ request.headers["Content-Length"]
55
+ # KeyError: 'Content-Length'
56
+ """
44
57
45
58
raw_request : bytes
46
59
"""Raw bytes passed to the constructor."""
@@ -111,4 +124,8 @@ def _parse_headers(header_bytes: bytes) -> Dict[str, str]:
111
124
"""Parse HTTP headers from raw request."""
112
125
header_lines = header_bytes .decode ("utf8" ).splitlines ()[1 :]
113
126
114
- return dict ([header .split (": " , 1 ) for header in header_lines [1 :]])
127
+ return {
128
+ name .lower (): value
129
+ for header_line in header_lines
130
+ for name , value in [header_line .split (": " , 1 )]
131
+ }
You can’t perform that action at this time.
0 commit comments