diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/http_parser_adaptor.h | 24 | ||||
-rw-r--r-- | src/inspector_socket.cc | 24 | ||||
-rw-r--r-- | src/node_binding.cc | 1 | ||||
-rw-r--r-- | src/node_http_parser.cc (renamed from src/node_http_parser_impl.h) | 108 | ||||
-rw-r--r-- | src/node_http_parser_llhttp.cc | 21 | ||||
-rw-r--r-- | src/node_http_parser_traditional.cc | 21 | ||||
-rw-r--r-- | src/node_metadata.cc | 9 | ||||
-rw-r--r-- | src/node_metadata.h | 3 | ||||
-rw-r--r-- | src/node_options.cc | 10 | ||||
-rw-r--r-- | src/node_options.h | 1 |
10 files changed, 31 insertions, 191 deletions
diff --git a/src/http_parser_adaptor.h b/src/http_parser_adaptor.h deleted file mode 100644 index 6d786bd095..0000000000 --- a/src/http_parser_adaptor.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SRC_HTTP_PARSER_ADAPTOR_H_ -#define SRC_HTTP_PARSER_ADAPTOR_H_ - -#ifdef NODE_EXPERIMENTAL_HTTP -# include "llhttp.h" - -typedef llhttp_type_t parser_type_t; -typedef llhttp_errno_t parser_errno_t; -typedef llhttp_settings_t parser_settings_t; -typedef llhttp_t parser_t; - -#else /* !NODE_EXPERIMENTAL_HTTP */ -# include "http_parser.h" - -typedef enum http_parser_type parser_type_t; -typedef enum http_errno parser_errno_t; -typedef http_parser_settings parser_settings_t; -typedef http_parser parser_t; - -#define HPE_USER HPE_UNKNOWN - -#endif /* NODE_EXPERIMENTAL_HTTP */ - -#endif /* SRC_HTTP_PARSER_ADAPTOR_H_ */ diff --git a/src/inspector_socket.cc b/src/inspector_socket.cc index a7019281af..ec34773240 100644 --- a/src/inspector_socket.cc +++ b/src/inspector_socket.cc @@ -1,12 +1,8 @@ #include "inspector_socket.h" +#include "llhttp.h" -#define NODE_EXPERIMENTAL_HTTP -#include "http_parser_adaptor.h" - -#include "util-inl.h" - -#define NODE_WANT_INTERNALS 1 #include "base64.h" +#include "util-inl.h" #include "openssl/sha.h" // Sha-1 hash @@ -479,7 +475,7 @@ class HttpHandler : public ProtocolHandler { } void OnData(std::vector<char>* data) override { - parser_errno_t err; + llhttp_errno_t err; err = llhttp_execute(&parser_, data->data(), data->size()); if (err == HPE_PAUSED_UPGRADE) { @@ -524,14 +520,14 @@ class HttpHandler : public ProtocolHandler { handler->inspector()->SwitchProtocol(nullptr); } - static int OnHeaderValue(parser_t* parser, const char* at, size_t length) { + static int OnHeaderValue(llhttp_t* parser, const char* at, size_t length) { HttpHandler* handler = From(parser); handler->parsing_value_ = true; handler->headers_[handler->current_header_].append(at, length); return 0; } - static int OnHeaderField(parser_t* parser, const char* at, size_t length) { + static int OnHeaderField(llhttp_t* parser, const char* at, size_t length) { HttpHandler* handler = From(parser); if (handler->parsing_value_) { handler->parsing_value_ = false; @@ -541,17 +537,17 @@ class HttpHandler : public ProtocolHandler { return 0; } - static int OnPath(parser_t* parser, const char* at, size_t length) { + static int OnPath(llhttp_t* parser, const char* at, size_t length) { HttpHandler* handler = From(parser); handler->path_.append(at, length); return 0; } - static HttpHandler* From(parser_t* parser) { + static HttpHandler* From(llhttp_t* parser) { return node::ContainerOf(&HttpHandler::parser_, parser); } - static int OnMessageComplete(parser_t* parser) { + static int OnMessageComplete(llhttp_t* parser) { // Event needs to be fired after the parser is done. HttpHandler* handler = From(parser); handler->events_.emplace_back(handler->path_, @@ -589,8 +585,8 @@ class HttpHandler : public ProtocolHandler { } bool parsing_value_; - parser_t parser_; - parser_settings_t parser_settings; + llhttp_t parser_; + llhttp_settings_t parser_settings; std::vector<HttpEvent> events_; std::string current_header_; std::map<std::string, std::string> headers_; diff --git a/src/node_binding.cc b/src/node_binding.cc index c51a892e1b..a2790d42aa 100644 --- a/src/node_binding.cc +++ b/src/node_binding.cc @@ -54,7 +54,6 @@ V(heap_utils) \ V(http2) \ V(http_parser) \ - V(http_parser_llhttp) \ V(inspector) \ V(js_stream) \ V(messaging) \ diff --git a/src/node_http_parser_impl.h b/src/node_http_parser.cc index 1afedb0509..3376986999 100644 --- a/src/node_http_parser_impl.h +++ b/src/node_http_parser.cc @@ -19,27 +19,22 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -// This file is included from 2 files, node_http_parser_traditional.cc -// and node_http_parser_llhttp.cc. - -#pragma once - #include "node.h" #include "node_buffer.h" #include "util.h" #include "async_wrap-inl.h" #include "env-inl.h" +#include "memory_tracker-inl.h" #include "stream_base-inl.h" #include "v8.h" - -#include "http_parser_adaptor.h" +#include "llhttp.h" #include <cstdlib> // free() #include <cstring> // strdup(), strchr() -// This is a binding to http_parser (https://github.com/nodejs/http-parser) +// This is a binding to llhttp (https://github.com/nodejs/llhttp) // The goal is to decouple sockets from parsing for more javascript-level // agility. A Buffer is read from a socket and passed to parser.execute(). // The parser then issues callbacks with slices of the data @@ -247,9 +242,7 @@ class Parser : public AsyncWrap, public StreamListener { int on_headers_complete() { -#ifdef NODE_EXPERIMENTAL_HTTP header_nread_ = 0; -#endif /* NODE_EXPERIMENTAL_HTTP */ // Arguments for the on-headers-complete javascript callback. This // list needs to be kept in sync with the actual argument list for @@ -310,11 +303,7 @@ class Parser : public AsyncWrap, public StreamListener { argv[A_VERSION_MINOR] = Integer::New(env()->isolate(), parser_.http_minor); bool should_keep_alive; -#ifdef NODE_EXPERIMENTAL_HTTP should_keep_alive = llhttp_should_keep_alive(&parser_); -#else /* !NODE_EXPERIMENTAL_HTTP */ - should_keep_alive = http_should_keep_alive(&parser_); -#endif /* NODE_EXPERIMENTAL_HTTP */ argv[A_SHOULD_KEEP_ALIVE] = Boolean::New(env()->isolate(), should_keep_alive); @@ -369,9 +358,7 @@ class Parser : public AsyncWrap, public StreamListener { if (r.IsEmpty()) { got_exception_ = true; -#ifdef NODE_EXPERIMENTAL_HTTP llhttp_set_error_reason(&parser_, "HPE_JS_EXCEPTION:JS Exception"); -#endif /* NODE_EXPERIMENTAL_HTTP */ return HPE_USER; } @@ -404,7 +391,6 @@ class Parser : public AsyncWrap, public StreamListener { return 0; } -#ifdef NODE_EXPERIMENTAL_HTTP // Reset nread for the next chunk int on_chunk_header() { header_nread_ = 0; @@ -417,8 +403,6 @@ class Parser : public AsyncWrap, public StreamListener { header_nread_ = 0; return 0; } -#endif /* NODE_EXPERIMENTAL_HTTP */ - static void New(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); @@ -499,8 +483,8 @@ class Parser : public AsyncWrap, public StreamListener { CHECK(args[0]->IsInt32()); CHECK(args[1]->IsObject()); - parser_type_t type = - static_cast<parser_type_t>(args[0].As<Int32>()->Value()); + llhttp_type_t type = + static_cast<llhttp_type_t>(args[0].As<Int32>()->Value()); CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE); Parser* parser; @@ -526,7 +510,6 @@ class Parser : public AsyncWrap, public StreamListener { // Should always be called from the same context. CHECK_EQ(env, parser->env()); -#ifdef NODE_EXPERIMENTAL_HTTP if (parser->execute_depth_) { parser->pending_pause_ = should_pause; return; @@ -537,9 +520,6 @@ class Parser : public AsyncWrap, public StreamListener { } else { llhttp_resume(&parser->parser_); } -#else /* !NODE_EXPERIMENTAL_HTTP */ - http_parser_pause(&parser->parser_, should_pause); -#endif /* NODE_EXPERIMENTAL_HTTP */ } @@ -647,9 +627,8 @@ class Parser : public AsyncWrap, public StreamListener { current_buffer_data_ = data; got_exception_ = false; - parser_errno_t err; + llhttp_errno_t err; -#ifdef NODE_EXPERIMENTAL_HTTP // Do not allow re-entering `http_parser_execute()` CHECK_EQ(execute_depth_, 0); @@ -679,31 +658,6 @@ class Parser : public AsyncWrap, public StreamListener { pending_pause_ = false; llhttp_pause(&parser_); } -#else /* !NODE_EXPERIMENTAL_HTTP */ - size_t nread = http_parser_execute(&parser_, &settings, data, len); - err = HTTP_PARSER_ERRNO(&parser_); - - // Finish() - if (data == nullptr) { - // `http_parser_execute()` returns either `0` or `1` when `len` is 0 - // (part of the finishing sequence). - CHECK_EQ(len, 0); - switch (nread) { - case 0: - err = HPE_OK; - break; - case 1: - nread = 0; - break; - default: - UNREACHABLE(); - } - - // Regular Execute() - } else { - Save(); - } -#endif /* NODE_EXPERIMENTAL_HTTP */ // Unassign the 'buffer_' variable current_buffer_.Clear(); @@ -725,7 +679,6 @@ class Parser : public AsyncWrap, public StreamListener { obj->Set(env()->context(), env()->bytes_parsed_string(), nread_obj).Check(); -#ifdef NODE_EXPERIMENTAL_HTTP const char* errno_reason = llhttp_get_error_reason(&parser_); Local<String> code; @@ -743,12 +696,6 @@ class Parser : public AsyncWrap, public StreamListener { obj->Set(env()->context(), env()->code_string(), code).Check(); obj->Set(env()->context(), env()->reason_string(), reason).Check(); -#else /* !NODE_EXPERIMENTAL_HTTP */ - obj->Set(env()->context(), - env()->code_string(), - OneByteString(env()->isolate(), - http_errno_name(err))).Check(); -#endif /* NODE_EXPERIMENTAL_HTTP */ return scope.Escape(e); } @@ -799,13 +746,9 @@ class Parser : public AsyncWrap, public StreamListener { } - void Init(parser_type_t type) { -#ifdef NODE_EXPERIMENTAL_HTTP + void Init(llhttp_type_t type) { llhttp_init(&parser_, type, &settings); header_nread_ = 0; -#else /* !NODE_EXPERIMENTAL_HTTP */ - http_parser_init(&parser_, type); -#endif /* NODE_EXPERIMENTAL_HTTP */ url_.Reset(); status_message_.Reset(); num_fields_ = 0; @@ -816,19 +759,16 @@ class Parser : public AsyncWrap, public StreamListener { int TrackHeader(size_t len) { -#ifdef NODE_EXPERIMENTAL_HTTP header_nread_ += len; if (header_nread_ >= per_process::cli_options->max_http_header_size) { llhttp_set_error_reason(&parser_, "HPE_HEADER_OVERFLOW:Header overflow"); return HPE_USER; } -#endif /* NODE_EXPERIMENTAL_HTTP */ return 0; } int MaybePause() { -#ifdef NODE_EXPERIMENTAL_HTTP CHECK_NE(execute_depth_, 0); if (!pending_pause_) { @@ -838,12 +778,9 @@ class Parser : public AsyncWrap, public StreamListener { pending_pause_ = false; llhttp_set_error_reason(&parser_, "Paused in callback"); return HPE_PAUSED; -#else /* !NODE_EXPERIMENTAL_HTTP */ - return 0; -#endif /* NODE_EXPERIMENTAL_HTTP */ } - parser_t parser_; + llhttp_t parser_; StringPtr fields_[kMaxHeaderFieldsCount]; // header fields StringPtr values_[kMaxHeaderFieldsCount]; // header values StringPtr url_; @@ -855,18 +792,16 @@ class Parser : public AsyncWrap, public StreamListener { Local<Object> current_buffer_; size_t current_buffer_len_; const char* current_buffer_data_; -#ifdef NODE_EXPERIMENTAL_HTTP unsigned int execute_depth_ = 0; bool pending_pause_ = false; uint64_t header_nread_ = 0; -#endif /* NODE_EXPERIMENTAL_HTTP */ // These are helper functions for filling `http_parser_settings`, which turn // a member function of Parser into a C-style HTTP parser callback. template <typename Parser, Parser> struct Proxy; template <typename Parser, typename ...Args, int (Parser::*Member)(Args...)> struct Proxy<int (Parser::*)(Args...), Member> { - static int Raw(parser_t* p, Args ... args) { + static int Raw(llhttp_t* p, Args ... args) { Parser* parser = ContainerOf(&Parser::parser_, p); int rv = (parser->*Member)(std::forward<Args>(args)...); if (rv == 0) { @@ -879,10 +814,10 @@ class Parser : public AsyncWrap, public StreamListener { typedef int (Parser::*Call)(); typedef int (Parser::*DataCall)(const char* at, size_t length); - static const parser_settings_t settings; + static const llhttp_settings_t settings; }; -const parser_settings_t Parser::settings = { +const llhttp_settings_t Parser::settings = { Proxy<Call, &Parser::on_message_begin>::Raw, Proxy<DataCall, &Parser::on_url>::Raw, Proxy<DataCall, &Parser::on_status>::Raw, @@ -891,25 +826,11 @@ const parser_settings_t Parser::settings = { Proxy<Call, &Parser::on_headers_complete>::Raw, Proxy<DataCall, &Parser::on_body>::Raw, Proxy<Call, &Parser::on_message_complete>::Raw, -#ifdef NODE_EXPERIMENTAL_HTTP Proxy<Call, &Parser::on_chunk_header>::Raw, Proxy<Call, &Parser::on_chunk_complete>::Raw, -#else /* !NODE_EXPERIMENTAL_HTTP */ - nullptr, - nullptr, -#endif /* NODE_EXPERIMENTAL_HTTP */ }; -#ifndef NODE_EXPERIMENTAL_HTTP -void InitMaxHttpHeaderSizeOnce() { - const uint32_t max_http_header_size = - per_process::cli_options->max_http_header_size; - http_parser_set_max_header_size(max_http_header_size); -} -#endif /* NODE_EXPERIMENTAL_HTTP */ - - void InitializeHttpParser(Local<Object> target, Local<Value> unused, Local<Context> context, @@ -959,12 +880,9 @@ void InitializeHttpParser(Local<Object> target, target->Set(env->context(), FIXED_ONE_BYTE_STRING(env->isolate(), "HTTPParser"), t->GetFunction(env->context()).ToLocalChecked()).Check(); - -#ifndef NODE_EXPERIMENTAL_HTTP - static uv_once_t init_once = UV_ONCE_INIT; - uv_once(&init_once, InitMaxHttpHeaderSizeOnce); -#endif /* NODE_EXPERIMENTAL_HTTP */ } } // anonymous namespace } // namespace node + +NODE_MODULE_CONTEXT_AWARE_INTERNAL(http_parser, node::InitializeHttpParser) diff --git a/src/node_http_parser_llhttp.cc b/src/node_http_parser_llhttp.cc deleted file mode 100644 index 6e1d18d3af..0000000000 --- a/src/node_http_parser_llhttp.cc +++ /dev/null @@ -1,21 +0,0 @@ -#define NODE_EXPERIMENTAL_HTTP 1 - -#include "node_http_parser_impl.h" -#include "memory_tracker-inl.h" -#include "node_metadata.h" -#include "util-inl.h" - -namespace node { - -namespace per_process { -const char* const llhttp_version = - NODE_STRINGIFY(LLHTTP_VERSION_MAJOR) - "." - NODE_STRINGIFY(LLHTTP_VERSION_MINOR) - "." - NODE_STRINGIFY(LLHTTP_VERSION_PATCH); -} // namespace per_process -} // namespace node - -NODE_MODULE_CONTEXT_AWARE_INTERNAL(http_parser_llhttp, - node::InitializeHttpParser) diff --git a/src/node_http_parser_traditional.cc b/src/node_http_parser_traditional.cc deleted file mode 100644 index 11aa387f10..0000000000 --- a/src/node_http_parser_traditional.cc +++ /dev/null @@ -1,21 +0,0 @@ -#ifdef NODE_EXPERIMENTAL_HTTP -#undef NODE_EXPERIMENTAL_HTTP -#endif - -#include "memory_tracker-inl.h" -#include "node_http_parser_impl.h" -#include "node_metadata.h" -#include "util-inl.h" - -namespace node { -namespace per_process { -const char* const http_parser_version = - NODE_STRINGIFY(HTTP_PARSER_VERSION_MAJOR) - "." - NODE_STRINGIFY(HTTP_PARSER_VERSION_MINOR) - "." - NODE_STRINGIFY(HTTP_PARSER_VERSION_PATCH); -} // namespace per_process -} // namespace node - -NODE_MODULE_CONTEXT_AWARE_INTERNAL(http_parser, node::InitializeHttpParser) diff --git a/src/node_metadata.cc b/src/node_metadata.cc index 8c787138b4..8d0a725de4 100644 --- a/src/node_metadata.cc +++ b/src/node_metadata.cc @@ -1,6 +1,7 @@ #include "node_metadata.h" #include "ares.h" #include "brotli/encode.h" +#include "llhttp.h" #include "nghttp2/nghttp2ver.h" #include "node.h" #include "util.h" @@ -72,8 +73,12 @@ Metadata::Versions::Versions() { modules = NODE_STRINGIFY(NODE_MODULE_VERSION); nghttp2 = NGHTTP2_VERSION; napi = NODE_STRINGIFY(NAPI_VERSION); - llhttp = per_process::llhttp_version; - http_parser = per_process::http_parser_version; + llhttp = + NODE_STRINGIFY(LLHTTP_VERSION_MAJOR) + "." + NODE_STRINGIFY(LLHTTP_VERSION_MINOR) + "." + NODE_STRINGIFY(LLHTTP_VERSION_PATCH); brotli = std::to_string(BrotliEncoderVersion() >> 24) + diff --git a/src/node_metadata.h b/src/node_metadata.h index c6f379f085..bf7e5d3ff4 100644 --- a/src/node_metadata.h +++ b/src/node_metadata.h @@ -31,7 +31,6 @@ namespace node { V(nghttp2) \ V(napi) \ V(llhttp) \ - V(http_parser) \ #if HAVE_OPENSSL #define NODE_VERSIONS_KEY_CRYPTO(V) V(openssl) @@ -102,8 +101,6 @@ class Metadata { // Per-process global namespace per_process { extern Metadata metadata; -extern const char* const llhttp_version; -extern const char* const http_parser_version; } } // namespace node diff --git a/src/node_options.cc b/src/node_options.cc index 286218fb19..8a88902513 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -154,10 +154,6 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors) { errors->push_back("either --check or --eval can be used, not both"); } - if (http_parser != "legacy" && http_parser != "llhttp") { - errors->push_back("invalid value for --http-parser"); - } - if (!unhandled_rejections.empty() && unhandled_rejections != "strict" && unhandled_rejections != "warn" && @@ -362,11 +358,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() { "Generate heap snapshot on specified signal", &EnvironmentOptions::heap_snapshot_signal, kAllowedInEnvironment); - AddOption("--http-parser", - "Select which HTTP parser to use; either 'legacy' or 'llhttp' " - "(default: llhttp).", - &EnvironmentOptions::http_parser, - kAllowedInEnvironment); + AddOption("--http-parser", "", NoOp{}, kAllowedInEnvironment); AddOption("--input-type", "set module type for string input", &EnvironmentOptions::module_type, diff --git a/src/node_options.h b/src/node_options.h index a15944aed9..161f9e76a0 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -113,7 +113,6 @@ class EnvironmentOptions : public Options { bool expose_internals = false; bool frozen_intrinsics = false; std::string heap_snapshot_signal; - std::string http_parser = "llhttp"; bool no_deprecation = false; bool no_force_async_hooks_checks = false; bool no_warnings = false; |