src: do not reuse async resource in http parsers · nodejs/node@ece5073 (original) (raw)
`@@ -152,11 +152,13 @@ struct StringPtr {
`
152
152
`size_t size_;
`
153
153
`};
`
154
154
``
155
``
-
156
155
`class Parser : public AsyncWrap, public StreamListener {
`
157
156
`public:
`
158
157
`Parser(Environment* env, Local wrap, parser_type_t type)
`
159
``
`-
: AsyncWrap(env, wrap, AsyncWrap::PROVIDER_HTTPPARSER),
`
``
158
`+
: AsyncWrap(env, wrap,
`
``
159
`+
type == HTTP_REQUEST ?
`
``
160
`+
AsyncWrap::PROVIDER_HTTPINCOMINGMESSAGE :
`
``
161
`+
AsyncWrap::PROVIDER_HTTPCLIENTREQUEST),
`
160
162
`current_buffer_len_(0),
`
161
163
` current_buffer_data_(nullptr) {
`
162
164
`Init(type);
`
`@@ -503,12 +505,12 @@ class Parser : public AsyncWrap, public StreamListener {
`
503
505
` }
`
504
506
``
505
507
``
506
``
`-
static void Reinitialize(const FunctionCallbackInfo& args) {
`
``
508
`+
static void Initialize(const FunctionCallbackInfo& args) {
`
507
509
` Environment* env = Environment::GetCurrent(args);
`
508
510
``
509
511
`CHECK(args[0]->IsInt32());
`
510
``
`-
CHECK(args[1]->IsBoolean());
`
511
``
`-
bool isReused = args[1]->IsTrue();
`
``
512
`+
CHECK(args[1]->IsObject());
`
``
513
+
512
514
`parser_type_t type =
`
513
515
`static_cast(args[0].As()->Value());
`
514
516
``
`@@ -517,16 +519,16 @@ class Parser : public AsyncWrap, public StreamListener {
`
517
519
`ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
`
518
520
`// Should always be called from the same context.
`
519
521
`CHECK_EQ(env, parser->env());
`
520
``
`-
// This parser has either just been created or it is being reused.
`
521
``
`-
// We must only call AsyncReset for the latter case, because AsyncReset has
`
522
``
`-
// already been called via the constructor for the former case.
`
523
``
`-
if (isReused) {
`
524
``
`-
parser->AsyncReset();
`
525
``
`-
}
`
``
522
+
``
523
`+
AsyncWrap::ProviderType provider =
`
``
524
`+
(type == HTTP_REQUEST ?
`
``
525
`+
AsyncWrap::PROVIDER_HTTPINCOMINGMESSAGE
`
``
526
`+
: AsyncWrap::PROVIDER_HTTPCLIENTREQUEST);
`
``
527
+
``
528
`+
parser->set_provider_type(provider);
`
526
529
` parser->Init(type);
`
527
530
` }
`
528
531
``
529
``
-
530
532
`template
`
531
533
`static void Pause(const FunctionCallbackInfo& args) {
`
532
534
` Environment* env = Environment::GetCurrent(args);
`
`@@ -958,7 +960,7 @@ void InitializeHttpParser(Local target,
`
958
960
` env->SetProtoMethod(t, "free", Parser::Free);
`
959
961
` env->SetProtoMethod(t, "execute", Parser::Execute);
`
960
962
` env->SetProtoMethod(t, "finish", Parser::Finish);
`
961
``
`-
env->SetProtoMethod(t, "reinitialize", Parser::Reinitialize);
`
``
963
`+
env->SetProtoMethod(t, "initialize", Parser::Initialize);
`
962
964
` env->SetProtoMethod(t, "pause", Parser::Pause);
`
963
965
` env->SetProtoMethod(t, "resume", Parser::Pause);
`
964
966
` env->SetProtoMethod(t, "consume", Parser::Consume);
`