Skip to content

Commit

Permalink
Update to LLHTTP 9 (#7485) (#7487)
Browse files Browse the repository at this point in the history
(cherry picked from commit c0c7508)
  • Loading branch information
Dreamsorcerer authored Aug 6, 2023
1 parent 8129d26 commit f92b27b
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "vendor/llhttp"]
path = vendor/llhttp
url = https://github.com/nodejs/llhttp.git
branch = v8.x
branch = main
1 change: 1 addition & 0 deletions CHANGES/7484.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgraded llhttp parser to v9 -- by :user:`Dreamsorcerer`
38 changes: 2 additions & 36 deletions aiohttp/_cparser.pxd
Original file line number Diff line number Diff line change
@@ -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":
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
15 changes: 2 additions & 13 deletions tests/test_http_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
[
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion vendor/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f92b27b

Please sign in to comment.