-
-
Save greentornado/69df26f6fbe044232398137833d8e41c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def output(self, version="1.1", keep_alive=False, keep_alive_timeout=None): | |
# This is all returned in a kind-of funky way | |
# We tried to make this as fast as possible in pure python | |
cdef bytes timeout_header | |
cdef bytes body | |
cdef bytes status | |
timeout_header = b"" | |
if keep_alive and keep_alive_timeout is not None: | |
timeout_header = b"Keep-Alive: %d\r\n" % keep_alive_timeout | |
body = b"" | |
if has_message_body(self.status): | |
body = self.body | |
self.headers["Content-Length"] = self.headers.get( | |
"Content-Length", len(self.body) | |
) | |
self.headers["Content-Type"] = self.headers.get( | |
"Content-Type", self.content_type | |
) | |
if self.status in (304, 412): | |
self.headers = remove_entity_headers(self.headers) | |
headers = self._parse_headers() | |
if self.status == 200: | |
status = b"OK" | |
else: | |
status = STATUS_CODES.get(self.status, b"UNKNOWN RESPONSE") | |
return ( | |
b"HTTP/%b %d %b\r\n" b"Connection: %b\r\n" b"%b" b"%b\r\n" b"%b" | |
) % ( | |
version.encode(), | |
self.status, | |
status, | |
b"keep-alive" if keep_alive else b"close", | |
timeout_header, | |
headers, | |
body, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment