From f8a7cc37b11d849fa662a87bf326f39cf22b3027 Mon Sep 17 00:00:00 2001 From: Sam Bull Date: Tue, 3 Oct 2023 16:43:54 +0100 Subject: [PATCH] Upgrade to llhttp 9.1.3 (#7647) (cherry picked from commit 1303350e834899ad1c7733effc716a1a46a4b817) --- aiohttp/_cparser.pxd | 2 ++ aiohttp/_http_parser.pyx | 2 ++ aiohttp/http_parser.py | 2 +- tests/test_http_parser.py | 2 +- vendor/llhttp | 2 +- 5 files changed, 7 insertions(+), 3 deletions(-) diff --git a/aiohttp/_cparser.pxd b/aiohttp/_cparser.pxd index 9dfb04134d1..c2cd5a92fda 100644 --- a/aiohttp/_cparser.pxd +++ b/aiohttp/_cparser.pxd @@ -154,3 +154,5 @@ cdef extern from "../vendor/llhttp/build/llhttp.h": const char* llhttp_method_name(llhttp_method_t method) void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) + void llhttp_set_lenient_optional_cr_before_lf(llhttp_t* parser, int enabled) + void llhttp_set_lenient_spaces_after_chunk_size(llhttp_t* parser, int enabled) diff --git a/aiohttp/_http_parser.pyx b/aiohttp/_http_parser.pyx index 92a70f5685f..2b4b844d05e 100644 --- a/aiohttp/_http_parser.pyx +++ b/aiohttp/_http_parser.pyx @@ -652,6 +652,8 @@ cdef class HttpResponseParser(HttpParser): # Use strict parsing on dev mode, so users are warned about broken servers. if not DEBUG: cparser.llhttp_set_lenient_headers(self._cparser, 1) + cparser.llhttp_set_lenient_optional_cr_before_lf(self._cparser, 1) + cparser.llhttp_set_lenient_spaces_after_chunk_size(self._cparser, 1) cdef object _on_status_complete(self): if self._buf: diff --git a/aiohttp/http_parser.py b/aiohttp/http_parser.py index 5a66ce4b9ee..982570396c6 100644 --- a/aiohttp/http_parser.py +++ b/aiohttp/http_parser.py @@ -498,7 +498,7 @@ def parse_headers( if hdrs.CONTENT_LENGTH in headers: raise BadHttpMessage( - "Content-Length can't be present with Transfer-Encoding", + "Transfer-Encoding can't be present with Content-Length", ) return (headers, raw_headers, close_conn, encoding, upgrade, chunked) diff --git a/tests/test_http_parser.py b/tests/test_http_parser.py index d1678296a5b..6c2067c6ec2 100644 --- a/tests/test_http_parser.py +++ b/tests/test_http_parser.py @@ -340,7 +340,7 @@ def test_request_te_chunked_with_content_length(parser: Any) -> None: ) with pytest.raises( http_exceptions.BadHttpMessage, - match="Content-Length can't be present with Transfer-Encoding", + match="Transfer-Encoding can't be present with Content-Length", ): parser.feed_data(text) diff --git a/vendor/llhttp b/vendor/llhttp index ea67741b1b7..9ab2afc85b2 160000 --- a/vendor/llhttp +++ b/vendor/llhttp @@ -1 +1 @@ -Subproject commit ea67741b1b70c52d43d8520bf1750e4a7427e827 +Subproject commit 9ab2afc85b2880d96a94d38afaee301c6a314049