From d718a62e199d22d11e8ca9dc6b8083fee52d5e6b Mon Sep 17 00:00:00 2001 From: Riccardo Schirone Date: Thu, 29 Sep 2022 16:28:20 +0200 Subject: [PATCH] http_parser: use backslashreplace when reporting LineTooLong error This should avoid problems when the line contains characters that cannot be decoded in the utf-8 encoding, which would generate a TypeError with the xmlcharrefreplace encoding. --- aiohttp/http_parser.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aiohttp/http_parser.py b/aiohttp/http_parser.py index dd1c0850e5e..fa214866f3c 100644 --- a/aiohttp/http_parser.py +++ b/aiohttp/http_parser.py @@ -154,7 +154,7 @@ def parse_headers( if len(bname) > self.max_field_size: raise LineTooLong( "request header name {}".format( - bname.decode("utf8", "xmlcharrefreplace") + bname.decode("utf8", "backslashreplace") ), str(self.max_field_size), str(len(bname)), @@ -176,7 +176,7 @@ def parse_headers( if header_length > self.max_field_size: raise LineTooLong( "request header field {}".format( - bname.decode("utf8", "xmlcharrefreplace") + bname.decode("utf8", "backslashreplace") ), str(self.max_field_size), str(header_length), @@ -197,7 +197,7 @@ def parse_headers( if header_length > self.max_field_size: raise LineTooLong( "request header field {}".format( - bname.decode("utf8", "xmlcharrefreplace") + bname.decode("utf8", "backslashreplace") ), str(self.max_field_size), str(header_length),