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:
4040 """HTTP version, e.g. "HTTP/1.1"."""
4141
4242 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+ """
4457
4558 raw_request : bytes
4659 """Raw bytes passed to the constructor."""
@@ -111,4 +124,8 @@ def _parse_headers(header_bytes: bytes) -> Dict[str, str]:
111124 """Parse HTTP headers from raw request."""
112125 header_lines = header_bytes .decode ("utf8" ).splitlines ()[1 :]
113126
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