Skip to content

Commit

Permalink
Refactor HTTPConnection class to simplify header
Browse files Browse the repository at this point in the history
retrieval
  • Loading branch information
abersheeran committed Nov 26, 2023
1 parent 6c67568 commit 5a1439a
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions baize/wsgi/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from itertools import chain
from typing import Any, Dict, Iterator, Mapping, Optional
from urllib.parse import parse_qsl

Expand Down Expand Up @@ -90,19 +89,12 @@ def headers(self) -> Headers:
Note that in its internal storage, all keys are in lower case.
"""
return Headers(
(key.lower().replace("_", "-"), value)
for key, value in chain(
(
(key[5:], value)
for key, value in self._environ.items()
if key.startswith("HTTP_")
),
(
(key, self._environ[key])
for key in ("CONTENT_TYPE", "CONTENT_LENGTH")
if key in self._environ
),
(
(key[5:] if key.startswith("HTTP_") else key).lower().replace("_", "-"),
value,
)
for key, value in self._environ.items()
if key.startswith("HTTP_") or key in ("CONTENT_TYPE", "CONTENT_LENGTH")
)


Expand Down

0 comments on commit 5a1439a

Please sign in to comment.