diff --git a/.gitmodules b/.gitmodules index 6edb2eea5b2..498bf7eb102 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "vendor/llhttp"] path = vendor/llhttp url = https://github.com/nodejs/llhttp.git - branch = v8.x + branch = main diff --git a/CHANGES/7484.misc b/CHANGES/7484.misc new file mode 100644 index 00000000000..ff540ceb709 --- /dev/null +++ b/CHANGES/7484.misc @@ -0,0 +1 @@ +Upgraded llhttp parser to v9 -- by :user:`Dreamsorcerer` diff --git a/aiohttp/_cparser.pxd b/aiohttp/_cparser.pxd index 165dd61d8a9..9dfb04134d1 100644 --- a/aiohttp/_cparser.pxd +++ b/aiohttp/_cparser.pxd @@ -1,13 +1,4 @@ -from libc.stdint cimport ( - int8_t, - int16_t, - int32_t, - int64_t, - uint8_t, - uint16_t, - uint32_t, - uint64_t, -) +from libc.stdint cimport int32_t, uint8_t, uint16_t, uint64_t cdef extern from "../vendor/llhttp/build/llhttp.h": @@ -88,30 +79,14 @@ cdef extern from "../vendor/llhttp/build/llhttp.h": ctypedef llhttp_errno llhttp_errno_t enum llhttp_flags: - F_CONNECTION_KEEP_ALIVE, - F_CONNECTION_CLOSE, - F_CONNECTION_UPGRADE, F_CHUNKED, - F_UPGRADE, - F_CONTENT_LENGTH, - F_SKIPBODY, - F_TRAILING, - F_TRANSFER_ENCODING - - enum llhttp_lenient_flags: - LENIENT_HEADERS, - LENIENT_CHUNKED_LENGTH + F_CONTENT_LENGTH enum llhttp_type: HTTP_REQUEST, HTTP_RESPONSE, HTTP_BOTH - enum llhttp_finish_t: - HTTP_FINISH_SAFE, - HTTP_FINISH_SAFE_WITH_CB, - HTTP_FINISH_UNSAFE - enum llhttp_method: HTTP_DELETE, HTTP_GET, @@ -167,24 +142,15 @@ cdef extern from "../vendor/llhttp/build/llhttp.h": const llhttp_settings_t* settings) llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len) - llhttp_errno_t llhttp_finish(llhttp_t* parser) - - int llhttp_message_needs_eof(const llhttp_t* parser) int llhttp_should_keep_alive(const llhttp_t* parser) - void llhttp_pause(llhttp_t* parser) - void llhttp_resume(llhttp_t* parser) - void llhttp_resume_after_upgrade(llhttp_t* parser) llhttp_errno_t llhttp_get_errno(const llhttp_t* parser) const char* llhttp_get_error_reason(const llhttp_t* parser) - void llhttp_set_error_reason(llhttp_t* parser, const char* reason) const char* llhttp_get_error_pos(const llhttp_t* parser) - const char* llhttp_errno_name(llhttp_errno_t err) const char* llhttp_method_name(llhttp_method_t method) void llhttp_set_lenient_headers(llhttp_t* parser, int enabled) - void llhttp_set_lenient_chunked_length(llhttp_t* parser, int enabled) diff --git a/tests/test_http_parser.py b/tests/test_http_parser.py index 344d0776633..e8d38c193bd 100644 --- a/tests/test_http_parser.py +++ b/tests/test_http_parser.py @@ -861,19 +861,6 @@ def test_partial_url(parser) -> None: assert payload.is_eof() -def test_url_parse_non_strict_mode(parser) -> None: - payload = "GET /test/тест HTTP/1.1\r\n\r\n".encode() - messages, upgrade, tail = parser.feed_data(payload) - assert len(messages) == 1 - - msg, payload = messages[0] - - assert msg.method == "GET" - assert msg.path == "/test/тест" - assert msg.version == (1, 1) - assert payload.is_eof() - - @pytest.mark.parametrize( ("uri", "path", "query", "fragment"), [ @@ -898,6 +885,8 @@ def test_parse_uri_percent_encoded(parser, uri, path, query, fragment) -> None: def test_parse_uri_utf8(parser) -> None: + if not isinstance(parser, HttpRequestParserPy): + pytest.xfail("Not valid HTTP. Maybe update py-parser to reject later.") text = ("GET /путь?ключ=знач#фраг HTTP/1.1\r\n\r\n").encode() messages, upgrade, tail = parser.feed_data(text) msg = messages[0][0] diff --git a/vendor/README.rst b/vendor/README.rst index 1f10e20cce2..6156f37f80e 100644 --- a/vendor/README.rst +++ b/vendor/README.rst @@ -5,7 +5,7 @@ When building aiohttp from source, there is a pure Python parser used by default For better performance, you may want to build the higher performance C parser. To build this ``llhttp`` parser, first get/update the submodules (to update to a -newer release, add ``--remote`` and check the branch in ``.gitmodules``):: +newer release, add ``--remote``):: git submodule update --init --recursive diff --git a/vendor/llhttp b/vendor/llhttp index 7e18596bae8..ea67741b1b7 160000 --- a/vendor/llhttp +++ b/vendor/llhttp @@ -1 +1 @@ -Subproject commit 7e18596bae8f63692ded9d3250d5d984fe90dcfb +Subproject commit ea67741b1b70c52d43d8520bf1750e4a7427e827