-
Notifications
You must be signed in to change notification settings - Fork 89
Swap http-parse to llhttp #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
0134161
782de1f
29e3a74
8e904cc
2063cc9
0deab69
b1aa3cd
9ba7243
52496e8
6fb3f2c
827f076
d26635c
23f6c1f
3dcded2
7199802
1f2f7f1
c234e2c
be9656e
e760899
d1ea341
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,7 @@ __pycache__/ | |
/.pytest_cache | ||
/.mypy_cache | ||
/.vscode | ||
vendor/llhttp/node_modules | ||
vendor/llhttp/build | ||
.eggs | ||
.venv |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
[submodule "vendor/http-parser"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like we no longer need the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi! Actually it is used to parse urls, as llhttp don't have this feature! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
path = vendor/http-parser | ||
url = https://github.com/nodejs/http-parser.git | ||
[submodule "vendor/llhttp"] | ||
path = vendor/llhttp | ||
url = https://github.com/nodejs/llhttp.git | ||
branch = release | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned earlier, we should remove the confusing |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .parser import * # NoQA | ||
from .errors import * # NoQA | ||
from .url_parser import * # NoQA | ||
|
||
__all__ = parser.__all__ + errors.__all__ # NoQA | ||
__all__ = parser.__all__ + errors.__all__ + url_parser.__all__ # NoQA |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,139 +1,156 @@ | ||||||
from libc.stdint cimport uint16_t, uint32_t, uint64_t | ||||||
from libc.stdint cimport int32_t, uint8_t, uint16_t, uint64_t | ||||||
|
||||||
|
||||||
cdef extern from "../../vendor/http-parser/http_parser.h": | ||||||
ctypedef int (*http_data_cb) (http_parser*, | ||||||
cdef extern from "../../vendor/llhttp/include/llhttp.h": | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This was a leftover issue - we should let the compiler find the right header files instead of hard-coding here - as we do support |
||||||
struct llhttp__internal_s: | ||||||
int32_t _index | ||||||
void *_span_pos0 | ||||||
void *_span_cb0 | ||||||
int32_t error | ||||||
const char *reason | ||||||
const char *error_pos | ||||||
void *data | ||||||
void *_current | ||||||
uint64_t content_length | ||||||
uint8_t type | ||||||
uint8_t method | ||||||
uint8_t http_major | ||||||
uint8_t http_minor | ||||||
uint8_t header_state | ||||||
uint16_t flags | ||||||
uint8_t upgrade | ||||||
uint16_t status_code | ||||||
uint8_t finish | ||||||
void *settings | ||||||
ctypedef llhttp__internal_s llhttp__internal_t | ||||||
ctypedef llhttp__internal_t llhttp_t | ||||||
|
||||||
ctypedef int (*llhttp_data_cb) (llhttp_t*, | ||||||
const char *at, | ||||||
size_t length) except -1 | ||||||
|
||||||
ctypedef int (*http_cb) (http_parser*) except -1 | ||||||
|
||||||
struct http_parser: | ||||||
unsigned int type | ||||||
unsigned int flags | ||||||
unsigned int state | ||||||
unsigned int header_state | ||||||
unsigned int index | ||||||
|
||||||
uint32_t nread | ||||||
uint64_t content_length | ||||||
|
||||||
unsigned short http_major | ||||||
unsigned short http_minor | ||||||
unsigned int status_code | ||||||
unsigned int method | ||||||
unsigned int http_errno | ||||||
|
||||||
unsigned int upgrade | ||||||
|
||||||
void *data | ||||||
|
||||||
struct http_parser_settings: | ||||||
http_cb on_message_begin | ||||||
http_data_cb on_url | ||||||
http_data_cb on_status | ||||||
http_data_cb on_header_field | ||||||
http_data_cb on_header_value | ||||||
http_cb on_headers_complete | ||||||
http_data_cb on_body | ||||||
http_cb on_message_complete | ||||||
http_cb on_chunk_header | ||||||
http_cb on_chunk_complete | ||||||
|
||||||
enum http_parser_type: | ||||||
ctypedef int (*llhttp_cb) (llhttp_t*) except -1 | ||||||
|
||||||
struct llhttp_settings_s: | ||||||
llhttp_cb on_message_begin | ||||||
llhttp_data_cb on_url | ||||||
llhttp_data_cb on_status | ||||||
llhttp_data_cb on_header_field | ||||||
llhttp_data_cb on_header_value | ||||||
llhttp_cb on_headers_complete | ||||||
llhttp_data_cb on_body | ||||||
llhttp_cb on_message_complete | ||||||
llhttp_cb on_chunk_header | ||||||
llhttp_cb on_chunk_complete | ||||||
ctypedef llhttp_settings_s llhttp_settings_t | ||||||
|
||||||
enum llhttp_type: | ||||||
HTTP_BOTH, | ||||||
HTTP_REQUEST, | ||||||
HTTP_RESPONSE, | ||||||
HTTP_BOTH | ||||||
HTTP_RESPONSE | ||||||
ctypedef llhttp_type llhttp_type_t | ||||||
|
||||||
enum http_errno: | ||||||
enum llhttp_errno: | ||||||
HPE_OK, | ||||||
HPE_CB_message_begin, | ||||||
HPE_CB_url, | ||||||
HPE_CB_header_field, | ||||||
HPE_CB_header_value, | ||||||
HPE_CB_headers_complete, | ||||||
HPE_CB_body, | ||||||
HPE_CB_message_complete, | ||||||
HPE_CB_status, | ||||||
HPE_CB_chunk_header, | ||||||
HPE_CB_chunk_complete, | ||||||
HPE_INVALID_EOF_STATE, | ||||||
HPE_HEADER_OVERFLOW, | ||||||
HPE_INTERNAL, | ||||||
HPE_STRICT, | ||||||
HPE_LF_EXPECTED, | ||||||
HPE_UNEXPECTED_CONTENT_LENGTH, | ||||||
HPE_CLOSED_CONNECTION, | ||||||
HPE_INVALID_VERSION, | ||||||
HPE_INVALID_STATUS, | ||||||
HPE_INVALID_METHOD, | ||||||
HPE_INVALID_URL, | ||||||
HPE_INVALID_HOST, | ||||||
HPE_INVALID_PORT, | ||||||
HPE_INVALID_PATH, | ||||||
HPE_INVALID_QUERY_STRING, | ||||||
HPE_INVALID_FRAGMENT, | ||||||
HPE_LF_EXPECTED, | ||||||
HPE_INVALID_CONSTANT, | ||||||
HPE_INVALID_VERSION, | ||||||
HPE_INVALID_HEADER_TOKEN, | ||||||
HPE_INVALID_CONTENT_LENGTH, | ||||||
HPE_INVALID_CHUNK_SIZE, | ||||||
HPE_INVALID_CONSTANT, | ||||||
HPE_INVALID_INTERNAL_STATE, | ||||||
HPE_STRICT, | ||||||
HPE_INVALID_STATUS, | ||||||
HPE_INVALID_EOF_STATE, | ||||||
HPE_INVALID_TRANSFER_ENCODING, | ||||||
HPE_CB_MESSAGE_BEGIN, | ||||||
HPE_CB_HEADERS_COMPLETE, | ||||||
HPE_CB_MESSAGE_COMPLETE, | ||||||
HPE_CB_CHUNK_HEADER, | ||||||
HPE_CB_CHUNK_COMPLETE, | ||||||
HPE_PAUSED, | ||||||
HPE_UNKNOWN | ||||||
HPE_PAUSED_UPGRADE, | ||||||
HPE_USER | ||||||
ctypedef llhttp_errno llhttp_errno_t | ||||||
|
||||||
enum flags: | ||||||
F_CHUNKED, | ||||||
enum llhttp_flags: | ||||||
F_CONNECTION_KEEP_ALIVE, | ||||||
F_CONNECTION_CLOSE, | ||||||
F_CONNECTION_UPGRADE, | ||||||
F_TRAILING, | ||||||
F_CHUNKED, | ||||||
F_UPGRADE, | ||||||
F_SKIPBODY | ||||||
|
||||||
enum http_method: | ||||||
DELETE, GET, HEAD, POST, PUT, CONNECT, OPTIONS, TRACE, COPY, | ||||||
LOCK, MKCOL, MOVE, PROPFIND, PROPPATCH, SEARCH, UNLOCK, BIND, | ||||||
REBIND, UNBIND, ACL, REPORT, MKACTIVITY, CHECKOUT, MERGE, | ||||||
MSEARCH, NOTIFY, SUBSCRIBE, UNSUBSCRIBE, PATCH, PURGE, MKCALENDAR, | ||||||
LINK, UNLINK | ||||||
|
||||||
void http_parser_init(http_parser *parser, http_parser_type type) | ||||||
|
||||||
size_t http_parser_execute(http_parser *parser, | ||||||
const http_parser_settings *settings, | ||||||
const char *data, | ||||||
size_t len) | ||||||
|
||||||
int http_should_keep_alive(const http_parser *parser) | ||||||
|
||||||
void http_parser_settings_init(http_parser_settings *settings) | ||||||
|
||||||
const char *http_errno_name(http_errno err) | ||||||
const char *http_errno_description(http_errno err) | ||||||
const char *http_method_str(http_method m) | ||||||
|
||||||
# URL Parser | ||||||
|
||||||
enum http_parser_url_fields: | ||||||
UF_SCHEMA = 0, | ||||||
UF_HOST = 1, | ||||||
UF_PORT = 2, | ||||||
UF_PATH = 3, | ||||||
UF_QUERY = 4, | ||||||
UF_FRAGMENT = 5, | ||||||
UF_USERINFO = 6, | ||||||
UF_MAX = 7 | ||||||
|
||||||
struct http_parser_url_field_data: | ||||||
uint16_t off | ||||||
uint16_t len | ||||||
|
||||||
struct http_parser_url: | ||||||
uint16_t field_set | ||||||
uint16_t port | ||||||
http_parser_url_field_data[<int>UF_MAX] field_data | ||||||
|
||||||
void http_parser_url_init(http_parser_url *u) | ||||||
|
||||||
int http_parser_parse_url(const char *buf, | ||||||
size_t buflen, | ||||||
int is_connect, | ||||||
http_parser_url *u) | ||||||
F_CONTENT_LENGTH, | ||||||
F_SKIPBODY, | ||||||
F_TRAILING, | ||||||
F_LENIENT, | ||||||
F_TRANSFER_ENCODING | ||||||
ctypedef llhttp_flags llhttp_flags_t | ||||||
|
||||||
enum llhttp_method: | ||||||
HTTP_DELETE, | ||||||
HTTP_GET, | ||||||
HTTP_HEAD, | ||||||
HTTP_POST, | ||||||
HTTP_PUT, | ||||||
HTTP_CONNECT, | ||||||
HTTP_OPTIONS, | ||||||
HTTP_TRACE, | ||||||
HTTP_COPY, | ||||||
HTTP_LOCK, | ||||||
HTTP_MKCOL, | ||||||
HTTP_MOVE, | ||||||
HTTP_PROPFIND, | ||||||
HTTP_PROPPATCH, | ||||||
HTTP_SEARCH, | ||||||
HTTP_UNLOCK, | ||||||
HTTP_BIND, | ||||||
HTTP_REBIND, | ||||||
HTTP_UNBIND, | ||||||
HTTP_ACL, | ||||||
HTTP_REPORT, | ||||||
HTTP_MKACTIVITY, | ||||||
HTTP_CHECKOUT, | ||||||
HTTP_MERGE, | ||||||
HTTP_MSEARCH, | ||||||
HTTP_NOTIFY, | ||||||
HTTP_SUBSCRIBE, | ||||||
HTTP_UNSUBSCRIBE, | ||||||
HTTP_PATCH, | ||||||
HTTP_PURGE, | ||||||
HTTP_MKCALENDAR, | ||||||
HTTP_LINK, | ||||||
HTTP_UNLINK, | ||||||
HTTP_SOURCE, | ||||||
HTTP_PRI, | ||||||
HTTP_DESCRIBE, | ||||||
HTTP_ANNOUNCE, | ||||||
HTTP_SETUP, | ||||||
HTTP_PLAY, | ||||||
HTTP_PAUSE, | ||||||
HTTP_TEARDOWN, | ||||||
HTTP_GET_PARAMETER, | ||||||
HTTP_SET_PARAMETER, | ||||||
HTTP_REDIRECT, | ||||||
HTTP_RECORD, | ||||||
HTTP_FLUSH | ||||||
ctypedef llhttp_method llhttp_method_t | ||||||
|
||||||
void llhttp_init(llhttp_t* parser, llhttp_type_t type, const llhttp_settings_t* settings) | ||||||
|
||||||
void llhttp_settings_init(llhttp_settings_t* settings) | ||||||
|
||||||
llhttp_errno_t llhttp_execute(llhttp_t* parser, const char* data, size_t len) | ||||||
|
||||||
void llhttp_resume_after_upgrade(llhttp_t* parser) | ||||||
|
||||||
int llhttp_should_keep_alive(const llhttp_t* parser) | ||||||
|
||||||
const char* llhttp_get_error_pos(const llhttp_t* parser) | ||||||
const char* llhttp_get_error_reason(const llhttp_t* parser) | ||||||
const char* llhttp_method_name(llhttp_method_t method) | ||||||
|
||||||
void llhttp_set_error_reason(llhttp_t* parser, const char* reason); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we pinned to llhttp
release/*
tags, this is not needed any more. (llhttp should have its own.gitignore
on thevx.x.x
tags and in themaster
branch, right?)