Skip to content

Commit

Permalink
Decode request/response headers
Browse files Browse the repository at this point in the history
  • Loading branch information
immerrr committed May 31, 2021
1 parent 991d36e commit dd43554
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions uvicorn/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def __init__(self, scope):
@property
def request_headers(self):
if self._request_headers is None:
self._request_headers = dict(self.scope['headers'])
self._request_headers = {
k.decode('ascii'): v.decode('ascii')
for k, v in self.scope['headers']
}
return self._request_headers

@property
Expand All @@ -144,7 +147,10 @@ def duration(self):
def on_asgi_message(self, message):
if message['type'] == 'http.response.start':
self.status_code = message['status']
self.response_headers = dict(message['headers'])
self.response_headers = {
k.decode('ascii'): v.decode('ascii')
for k, v in message['headers']
}
elif message['type'] == 'http.response.body':
self.response_length += len(message.get('body', ''))

Expand Down

0 comments on commit dd43554

Please sign in to comment.