From 990ac52a1aededac4b185b8a721510e01d0cbca2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Sun, 8 Mar 2020 14:17:38 +0200 Subject: [PATCH] Header values should be strictly ASCII but both UTF-8 and Latin-1 exist. Use UTF-8B to cope with all. --- sanic/http.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sanic/http.py b/sanic/http.py index 7e616724..7896086f 100644 --- a/sanic/http.py +++ b/sanic/http.py @@ -120,7 +120,8 @@ class Http: raise PayloadTooLarge("Request header exceeds the size limit") # Parse header content try: - reqline, *raw_headers = buf[:pos].decode().split("\r\n") + raw_headers = buf[:pos].decode(errors="surrogateescape") + reqline, *raw_headers = raw_headers.split("\r\n") method, self.url, protocol = reqline.split(" ") if protocol == "HTTP/1.1": self.keep_alive = True