From eb1146c6b66827b6178980353e35e68c83f9619f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?W=C3=A8i=20C=C5=8Dngru=C3=AC?= Date: Thu, 14 Sep 2017 18:40:20 +0800 Subject: [PATCH] fix #763, sanic can't decode latin1 encoded header value --- sanic/server.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sanic/server.py b/sanic/server.py index f62ba654..4dedc650 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -189,10 +189,12 @@ class HttpProtocol(asyncio.Protocol): and int(value) > self.request_max_size: exception = PayloadTooLarge('Payload Too Large') self.write_error(exception) - + try: + value = value.decode() + except UnicodeDecodeError: + value = value.decode('latin_1') self.headers.append( - (self._header_fragment.decode().casefold(), - value.decode())) + (self._header_fragment.decode().casefold(), value)) self._header_fragment = b''