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: if keep_alive and keep_alive_timeout:
timeout_header = b'Keep-Alive: timeout=%d\r\n' % 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'' headers = b''
if self.headers: if self.headers:
headers = b''.join( 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) if isinstance(value, str) or isinstance(value, Cookie)
else b'%b: %b\r\n' % (name.encode(), else format_headers(name, str(value))
str(value).encode('utf-8'))
for name, value in self.headers.items() for name, value in self.headers.items()
) )