Skip to content

Commit

Permalink
header format function
Browse files Browse the repository at this point in the history
  • Loading branch information
r0fls committed Dec 25, 2016
1 parent 00b5a49 commit 7d7cbaa
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions sanic/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ def output(self, version="1.1", keep_alive=False, keep_alive_timeout=None):
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()
)

Expand Down

0 comments on commit 7d7cbaa

Please sign in to comment.