header format function

This commit is contained in:
Raphael Deem 2016-12-17 21:32:48 -08:00
parent 00b5a496dd
commit 7d7cbaacf1

View File

@ -94,13 +94,15 @@ class HTTPResponse:
if keep_alive and keep_alive_timeout:
timeout_header = b'Keep-Alive: timeout=%d\r\n' % keep_alive_timeout
format_headers = lambda name, value: b'%b: %b\r\n' %\
(name.encode(), value.encode('utf-8'))
headers = b''
if self.headers:
headers = b''.join(
b'%b: %b\r\n' % (name.encode(), value.encode('utf-8'))
format_headers(name, value)
if isinstance(value, str) or isinstance(value, Cookie)
else b'%b: %b\r\n' % (name.encode(),
str(value).encode('utf-8'))
else format_headers(name, str(value))
for name, value in self.headers.items()
)