Black format changes
This commit is contained in:
parent
d3adfd824c
commit
be20bb12e7
3 changed files with 17 additions and 9 deletions
|
|
@ -72,7 +72,9 @@ class HTTPHeaders:
|
|||
|
||||
def update(self, headers: Dict[str, str]):
|
||||
"""Updates the headers with the given dict."""
|
||||
return self._storage.update({key.lower(): [key, value] for key, value in headers.items()})
|
||||
return self._storage.update(
|
||||
{key.lower(): [key, value] for key, value in headers.items()}
|
||||
)
|
||||
|
||||
def copy(self):
|
||||
"""Returns a copy of the headers."""
|
||||
|
|
@ -97,4 +99,4 @@ class HTTPHeaders:
|
|||
return key.lower() in self._storage.keys()
|
||||
|
||||
def __repr__(self):
|
||||
return f'{self.__class__.__name__}({dict(self._storage.values())})'
|
||||
return f"{self.__class__.__name__}({dict(self._storage.values())})"
|
||||
|
|
|
|||
|
|
@ -119,8 +119,10 @@ class HTTPRequest:
|
|||
"""Parse HTTP headers from raw request."""
|
||||
header_lines = header_bytes.decode("utf8").splitlines()[1:]
|
||||
|
||||
return HTTPHeaders({
|
||||
name: value
|
||||
for header_line in header_lines
|
||||
for name, value in [header_line.split(": ", 1)]
|
||||
})
|
||||
return HTTPHeaders(
|
||||
{
|
||||
name: value
|
||||
for header_line in header_lines
|
||||
for name, value in [header_line.split(": ", 1)]
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ class HTTPResponse:
|
|||
"""
|
||||
self.status = status if isinstance(status, HTTPStatus) else HTTPStatus(*status)
|
||||
self.body = body
|
||||
self.headers = headers.copy() if isinstance(headers, HTTPHeaders) else HTTPHeaders(headers)
|
||||
self.headers = (
|
||||
headers.copy() if isinstance(headers, HTTPHeaders) else HTTPHeaders(headers)
|
||||
)
|
||||
self.content_type = content_type
|
||||
self.filename = filename
|
||||
self.root_path = root_path
|
||||
|
|
@ -73,7 +75,9 @@ class HTTPResponse:
|
|||
response = f"{http_version} {status.code} {status.text}\r\n"
|
||||
|
||||
headers.setdefault("Content-Type", content_type)
|
||||
headers.setdefault("Content-Length", content_length or len(body.encode("utf-8")))
|
||||
headers.setdefault(
|
||||
"Content-Length", content_length or len(body.encode("utf-8"))
|
||||
)
|
||||
headers.setdefault("Connection", "close")
|
||||
|
||||
for header, value in headers.items():
|
||||
|
|
|
|||
Loading…
Reference in a new issue