http: switch default parser to llhttp
Refs: https://github.com/nodejs/node/pull/24739 Fixes: https://github.com/nodejs/node/issues/24730 PR-URL: https://github.com/nodejs/node/pull/24870 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
951b1c3e09
commit
2cb8f24751
@ -187,7 +187,7 @@ parser.add_option('--openssl-system-ca-path',
|
|||||||
parser.add_option('--experimental-http-parser',
|
parser.add_option('--experimental-http-parser',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
dest='experimental_http_parser',
|
dest='experimental_http_parser',
|
||||||
help='use llhttp instead of http_parser by default')
|
help='(no-op)')
|
||||||
|
|
||||||
shared_optgroup.add_option('--shared-http-parser',
|
shared_optgroup.add_option('--shared-http-parser',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -1118,9 +1118,6 @@ def configure_node(o):
|
|||||||
else:
|
else:
|
||||||
o['variables']['node_target_type'] = 'executable'
|
o['variables']['node_target_type'] = 'executable'
|
||||||
|
|
||||||
o['variables']['node_experimental_http_parser'] = \
|
|
||||||
b(options.experimental_http_parser)
|
|
||||||
|
|
||||||
def configure_library(lib, output):
|
def configure_library(lib, output):
|
||||||
shared_lib = 'shared_' + lib
|
shared_lib = 'shared_' + lib
|
||||||
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
|
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
|
||||||
|
@ -129,7 +129,7 @@ Chooses an HTTP parser library. Available values are:
|
|||||||
- `llhttp` for https://llhttp.org/
|
- `llhttp` for https://llhttp.org/
|
||||||
- `legacy` for https://github.com/nodejs/http-parser
|
- `legacy` for https://github.com/nodejs/http-parser
|
||||||
|
|
||||||
The default is `legacy`, unless otherwise specified when building Node.js.
|
The default is `llhttp`, unless otherwise specified when building Node.js.
|
||||||
|
|
||||||
This flag exists to aid in experimentation with the internal implementation of
|
This flag exists to aid in experimentation with the internal implementation of
|
||||||
the Node.js http parser.
|
the Node.js http parser.
|
||||||
|
1
node.gyp
1
node.gyp
@ -12,7 +12,6 @@
|
|||||||
'force_dynamic_crt%': 0,
|
'force_dynamic_crt%': 0,
|
||||||
'node_module_version%': '',
|
'node_module_version%': '',
|
||||||
'node_shared_zlib%': 'false',
|
'node_shared_zlib%': 'false',
|
||||||
'node_experimental_http_parser%': 'false',
|
|
||||||
'node_shared_http_parser%': 'false',
|
'node_shared_http_parser%': 'false',
|
||||||
'node_shared_cares%': 'false',
|
'node_shared_cares%': 'false',
|
||||||
'node_shared_libuv%': 'false',
|
'node_shared_libuv%': 'false',
|
||||||
|
@ -163,10 +163,6 @@
|
|||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
|
|
||||||
[ 'node_experimental_http_parser=="true"', {
|
|
||||||
'defines': [ 'NODE_EXPERIMENTAL_HTTP_DEFAULT' ],
|
|
||||||
} ],
|
|
||||||
|
|
||||||
[ 'node_shared_http_parser=="false"', {
|
[ 'node_shared_http_parser=="false"', {
|
||||||
'dependencies': [
|
'dependencies': [
|
||||||
'deps/http_parser/http_parser.gyp:http_parser',
|
'deps/http_parser/http_parser.gyp:http_parser',
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#include "inspector_socket.h"
|
#include "inspector_socket.h"
|
||||||
|
|
||||||
#ifdef NODE_EXPERIMENTAL_HTTP_DEFAULT
|
|
||||||
#define NODE_EXPERIMENTAL_HTTP
|
#define NODE_EXPERIMENTAL_HTTP
|
||||||
#endif
|
|
||||||
#include "http_parser_adaptor.h"
|
#include "http_parser_adaptor.h"
|
||||||
|
|
||||||
#include "util-inl.h"
|
#include "util-inl.h"
|
||||||
@ -437,13 +435,8 @@ class HttpHandler : public ProtocolHandler {
|
|||||||
explicit HttpHandler(InspectorSocket* inspector, TcpHolder::Pointer tcp)
|
explicit HttpHandler(InspectorSocket* inspector, TcpHolder::Pointer tcp)
|
||||||
: ProtocolHandler(inspector, std::move(tcp)),
|
: ProtocolHandler(inspector, std::move(tcp)),
|
||||||
parsing_value_(false) {
|
parsing_value_(false) {
|
||||||
#ifdef NODE_EXPERIMENTAL_HTTP_DEFAULT
|
|
||||||
llhttp_init(&parser_, HTTP_REQUEST, &parser_settings);
|
llhttp_init(&parser_, HTTP_REQUEST, &parser_settings);
|
||||||
llhttp_settings_init(&parser_settings);
|
llhttp_settings_init(&parser_settings);
|
||||||
#else /* !NODE_EXPERIMENTAL_HTTP_DEFAULT */
|
|
||||||
http_parser_init(&parser_, HTTP_REQUEST);
|
|
||||||
http_parser_settings_init(&parser_settings);
|
|
||||||
#endif /* NODE_EXPERIMENTAL_HTTP_DEFAULT */
|
|
||||||
parser_settings.on_header_field = OnHeaderField;
|
parser_settings.on_header_field = OnHeaderField;
|
||||||
parser_settings.on_header_value = OnHeaderValue;
|
parser_settings.on_header_value = OnHeaderValue;
|
||||||
parser_settings.on_message_complete = OnMessageComplete;
|
parser_settings.on_message_complete = OnMessageComplete;
|
||||||
@ -488,17 +481,12 @@ class HttpHandler : public ProtocolHandler {
|
|||||||
|
|
||||||
void OnData(std::vector<char>* data) override {
|
void OnData(std::vector<char>* data) override {
|
||||||
parser_errno_t err;
|
parser_errno_t err;
|
||||||
#ifdef NODE_EXPERIMENTAL_HTTP_DEFAULT
|
|
||||||
err = llhttp_execute(&parser_, data->data(), data->size());
|
err = llhttp_execute(&parser_, data->data(), data->size());
|
||||||
|
|
||||||
if (err == HPE_PAUSED_UPGRADE) {
|
if (err == HPE_PAUSED_UPGRADE) {
|
||||||
err = HPE_OK;
|
err = HPE_OK;
|
||||||
llhttp_resume_after_upgrade(&parser_);
|
llhttp_resume_after_upgrade(&parser_);
|
||||||
}
|
}
|
||||||
#else /* !NODE_EXPERIMENTAL_HTTP_DEFAULT */
|
|
||||||
http_parser_execute(&parser_, &parser_settings, data->data(), data->size());
|
|
||||||
err = HTTP_PARSER_ERRNO(&parser_);
|
|
||||||
#endif /* NODE_EXPERIMENTAL_HTTP_DEFAULT */
|
|
||||||
data->clear();
|
data->clear();
|
||||||
if (err != HPE_OK) {
|
if (err != HPE_OK) {
|
||||||
CancelHandshake();
|
CancelHandshake();
|
||||||
|
@ -111,11 +111,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
|
|||||||
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
|
AddOption("--expose-internals", "", &EnvironmentOptions::expose_internals);
|
||||||
AddOption("--http-parser",
|
AddOption("--http-parser",
|
||||||
"Select which HTTP parser to use; either 'legacy' or 'llhttp' "
|
"Select which HTTP parser to use; either 'legacy' or 'llhttp' "
|
||||||
#ifdef NODE_EXPERIMENTAL_HTTP_DEFAULT
|
|
||||||
"(default: llhttp).",
|
"(default: llhttp).",
|
||||||
#else
|
|
||||||
"(default: legacy).",
|
|
||||||
#endif
|
|
||||||
&EnvironmentOptions::http_parser,
|
&EnvironmentOptions::http_parser,
|
||||||
kAllowedInEnvironment);
|
kAllowedInEnvironment);
|
||||||
AddOption("--loader",
|
AddOption("--loader",
|
||||||
|
@ -97,12 +97,7 @@ class EnvironmentOptions : public Options {
|
|||||||
bool experimental_vm_modules = false;
|
bool experimental_vm_modules = false;
|
||||||
bool experimental_worker = false;
|
bool experimental_worker = false;
|
||||||
bool expose_internals = false;
|
bool expose_internals = false;
|
||||||
std::string http_parser =
|
std::string http_parser = "llhttp";
|
||||||
#ifdef NODE_EXPERIMENTAL_HTTP_DEFAULT
|
|
||||||
"llhttp";
|
|
||||||
#else
|
|
||||||
"legacy";
|
|
||||||
#endif
|
|
||||||
bool no_deprecation = false;
|
bool no_deprecation = false;
|
||||||
bool no_force_async_hooks_checks = false;
|
bool no_force_async_hooks_checks = false;
|
||||||
bool no_warnings = false;
|
bool no_warnings = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user