GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: node_http_parser.cc Lines: 514 572 89.9 %
Date: 2022-06-23 04:15:39 Branches: 231 310 74.5 %

Line Branch Exec Source
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
#include "node.h"
23
#include "node_buffer.h"
24
#include "util.h"
25
26
#include "async_wrap-inl.h"
27
#include "env-inl.h"
28
#include "memory_tracker-inl.h"
29
#include "stream_base-inl.h"
30
#include "v8.h"
31
#include "llhttp.h"
32
33
#include <cstdlib>  // free()
34
#include <cstring>  // strdup(), strchr()
35
36
37
// This is a binding to llhttp (https://github.com/nodejs/llhttp)
38
// The goal is to decouple sockets from parsing for more javascript-level
39
// agility. A Buffer is read from a socket and passed to parser.execute().
40
// The parser then issues callbacks with slices of the data
41
//     parser.onMessageBegin
42
//     parser.onPath
43
//     parser.onBody
44
//     ...
45
// No copying is performed when slicing the buffer, only small reference
46
// allocations.
47
48
49
namespace node {
50
namespace {  // NOLINT(build/namespaces)
51
52
using v8::Array;
53
using v8::Boolean;
54
using v8::Context;
55
using v8::EscapableHandleScope;
56
using v8::Exception;
57
using v8::Function;
58
using v8::FunctionCallbackInfo;
59
using v8::FunctionTemplate;
60
using v8::HandleScope;
61
using v8::Int32;
62
using v8::Integer;
63
using v8::Isolate;
64
using v8::Local;
65
using v8::MaybeLocal;
66
using v8::Number;
67
using v8::Object;
68
using v8::String;
69
using v8::Uint32;
70
using v8::Undefined;
71
using v8::Value;
72
73
const uint32_t kOnMessageBegin = 0;
74
const uint32_t kOnHeaders = 1;
75
const uint32_t kOnHeadersComplete = 2;
76
const uint32_t kOnBody = 3;
77
const uint32_t kOnMessageComplete = 4;
78
const uint32_t kOnExecute = 5;
79
const uint32_t kOnTimeout = 6;
80
// Any more fields than this will be flushed into JS
81
const size_t kMaxHeaderFieldsCount = 32;
82
83
const uint32_t kLenientNone = 0;
84
const uint32_t kLenientHeaders = 1 << 0;
85
const uint32_t kLenientChunkedLength = 1 << 1;
86
const uint32_t kLenientKeepAlive = 1 << 2;
87
const uint32_t kLenientAll = kLenientHeaders | kLenientChunkedLength |
88
  kLenientKeepAlive;
89
90
18863
inline bool IsOWS(char c) {
91

18863
  return c == ' ' || c == '\t';
92
}
93
94
class BindingData : public BaseObject {
95
 public:
96
1050
  BindingData(Environment* env, Local<Object> obj)
97
1050
      : BaseObject(env, obj) {}
98
99
  static constexpr FastStringKey type_name { "http_parser" };
100
101
  std::vector<char> parser_buffer;
102
  bool parser_buffer_in_use = false;
103
104
3
  void MemoryInfo(MemoryTracker* tracker) const override {
105
3
    tracker->TrackField("parser_buffer", parser_buffer);
106
3
  }
107
3
  SET_SELF_SIZE(BindingData)
108
3
  SET_MEMORY_INFO_NAME(BindingData)
109
};
110
111
// helper class for the Parser
112
struct StringPtr {
113
341088
  StringPtr() {
114
341088
    on_heap_ = false;
115
341088
    Reset();
116
341088
  }
117
118
119
675444
  ~StringPtr() {
120
337722
    Reset();
121
337722
  }
122
123
124
  // If str_ does not point to a heap string yet, this function makes it do
125
  // so. This is called at the end of each http_parser_execute() so as not
126
  // to leak references. See issue #2438 and test-http-parser-bad-ref.js.
127
15864
  void Save() {
128

15864
    if (!on_heap_ && size_ > 0) {
129
6695
      char* s = new char[size_];
130
6695
      memcpy(s, str_, size_);
131
6695
      str_ = s;
132
6695
      on_heap_ = true;
133
    }
134
15864
  }
135
136
137
765256
  void Reset() {
138
765256
    if (on_heap_) {
139
6643
      delete[] str_;
140
6643
      on_heap_ = false;
141
    }
142
143
765256
    str_ = nullptr;
144
765256
    size_ = 0;
145
765256
  }
146
147
148
55571
  void Update(const char* str, size_t size) {
149
55571
    if (str_ == nullptr) {
150
55511
      str_ = str;
151

60
    } else if (on_heap_ || str_ + size_ != str) {
152
      // Non-consecutive input, make a copy on the heap.
153
      // TODO(bnoordhuis) Use slab allocation, O(n) allocs is bad.
154
60
      char* s = new char[size_ + size];
155
60
      memcpy(s, str_, size_);
156
60
      memcpy(s + size_, str, size);
157
158
60
      if (on_heap_)
159
59
        delete[] str_;
160
      else
161
1
        on_heap_ = true;
162
163
60
      str_ = s;
164
    }
165
55571
    size_ += size;
166
55571
  }
167
168
169
55419
  Local<String> ToString(Environment* env) const {
170
55419
    if (size_ != 0)
171
55354
      return OneByteString(env->isolate(), str_, size_);
172
    else
173
130
      return String::Empty(env->isolate());
174
  }
175
176
177
  // Strip trailing OWS (SPC or HTAB) from string.
178
18865
  Local<String> ToTrimmedString(Environment* env) {
179

18865
    while (size_ > 0 && IsOWS(str_[size_ - 1])) {
180
11
      size_--;
181
    }
182
18854
    return ToString(env);
183
  }
184
185
186
  const char* str_;
187
  bool on_heap_;
188
  size_t size_;
189
};
190
191
class Parser;
192
193
struct ParserComparator {
194
  bool operator()(const Parser* lhs, const Parser* rhs) const;
195
};
196
197
class ConnectionsList : public BaseObject {
198
 public:
199
    static void New(const FunctionCallbackInfo<Value>& args);
200
201
    static void All(const FunctionCallbackInfo<Value>& args);
202
203
    static void Idle(const FunctionCallbackInfo<Value>& args);
204
205
    static void Active(const FunctionCallbackInfo<Value>& args);
206
207
    static void Expired(const FunctionCallbackInfo<Value>& args);
208
209
30498
    void Push(Parser* parser) {
210
30498
      all_connections_.insert(parser);
211
30498
    }
212
213
30483
    void Pop(Parser* parser) {
214
30483
      all_connections_.erase(parser);
215
30483
    }
216
217
16514
    void PushActive(Parser* parser) {
218
16514
      active_connections_.insert(parser);
219
16514
    }
220
221
30483
    void PopActive(Parser* parser) {
222
30483
      active_connections_.erase(parser);
223
30483
    }
224
225
    SET_NO_MEMORY_INFO()
226
    SET_MEMORY_INFO_NAME(ConnectionsList)
227
    SET_SELF_SIZE(ConnectionsList)
228
229
 private:
230
564
    ConnectionsList(Environment* env, Local<Object> object)
231
564
      : BaseObject(env, object) {
232
564
        MakeWeak();
233
564
      }
234
235
    std::set<Parser*, ParserComparator> all_connections_;
236
    std::set<Parser*, ParserComparator> active_connections_;
237
};
238
239
class Parser : public AsyncWrap, public StreamListener {
240
  friend class ConnectionsList;
241
  friend struct ParserComparator;
242
243
 public:
244
5168
  Parser(BindingData* binding_data, Local<Object> wrap)
245
5168
      : AsyncWrap(binding_data->env(), wrap),
246
        current_buffer_len_(0),
247
        current_buffer_data_(nullptr),
248

335920
        binding_data_(binding_data) {
249
5168
  }
250
251
  SET_NO_MEMORY_INFO()
252
  SET_MEMORY_INFO_NAME(Parser)
253
  SET_SELF_SIZE(Parser)
254
255
17706
  int on_message_begin() {
256
    // Important: Pop from the lists BEFORE resetting the last_message_start_
257
    // otherwise std::set.erase will fail.
258
17706
    if (connectionsList_ != nullptr) {
259
14042
      connectionsList_->Pop(this);
260
14042
      connectionsList_->PopActive(this);
261
    }
262
263
17706
    num_fields_ = num_values_ = 0;
264
17706
    headers_completed_ = false;
265
17706
    last_message_start_ = uv_hrtime();
266
17706
    url_.Reset();
267
17706
    status_message_.Reset();
268
269
17706
    if (connectionsList_ != nullptr) {
270
14042
      connectionsList_->Push(this);
271
14042
      connectionsList_->PushActive(this);
272
    }
273
274
35412
    Local<Value> cb = object()->Get(env()->context(), kOnMessageBegin)
275
17706
                              .ToLocalChecked();
276
17706
    if (cb->IsFunction()) {
277
      InternalCallbackScope callback_scope(
278
        this, InternalCallbackScope::kSkipTaskQueues);
279
280
      MaybeLocal<Value> r = cb.As<Function>()->Call(
281
        env()->context(), object(), 0, nullptr);
282
283
      if (r.IsEmpty()) callback_scope.MarkAsFailed();
284
    }
285
286
17706
    return 0;
287
  }
288
289
290
14208
  int on_url(const char* at, size_t length) {
291
14208
    int rv = TrackHeader(length);
292
14208
    if (rv != 0) {
293
      return rv;
294
    }
295
296
14208
    url_.Update(at, length);
297
14208
    return 0;
298
  }
299
300
301
3490
  int on_status(const char* at, size_t length) {
302
3490
    int rv = TrackHeader(length);
303
3490
    if (rv != 0) {
304
      return rv;
305
    }
306
307
3490
    status_message_.Update(at, length);
308
3490
    return 0;
309
  }
310
311
312
18955
  int on_header_field(const char* at, size_t length) {
313
18955
    int rv = TrackHeader(length);
314
18955
    if (rv != 0) {
315
      return rv;
316
    }
317
318
18955
    if (num_fields_ == num_values_) {
319
      // start of new field name
320
18926
      num_fields_++;
321
18926
      if (num_fields_ == kMaxHeaderFieldsCount) {
322
        // ran out of space - flush to javascript land
323
47
        Flush();
324
47
        num_fields_ = 1;
325
47
        num_values_ = 0;
326
      }
327
18926
      fields_[num_fields_ - 1].Reset();
328
    }
329
330
18955
    CHECK_LT(num_fields_, kMaxHeaderFieldsCount);
331
18955
    CHECK_EQ(num_fields_, num_values_ + 1);
332
333
18955
    fields_[num_fields_ - 1].Update(at, length);
334
335
18955
    return 0;
336
  }
337
338
339
18935
  int on_header_value(const char* at, size_t length) {
340
18935
    int rv = TrackHeader(length);
341
18935
    if (rv != 0) {
342
17
      return rv;
343
    }
344
345
18918
    if (num_values_ != num_fields_) {
346
      // start of new header value
347
18895
      num_values_++;
348
18895
      values_[num_values_ - 1].Reset();
349
    }
350
351
18918
    CHECK_LT(num_values_, arraysize(values_));
352
18918
    CHECK_EQ(num_values_, num_fields_);
353
354
18918
    values_[num_values_ - 1].Update(at, length);
355
356
18918
    return 0;
357
  }
358
359
360
17650
  int on_headers_complete() {
361
17650
    headers_completed_ = true;
362
17650
    header_nread_ = 0;
363
364
    // Arguments for the on-headers-complete javascript callback. This
365
    // list needs to be kept in sync with the actual argument list for
366
    // `parserOnHeadersComplete` in lib/_http_common.js.
367
    enum on_headers_complete_arg_index {
368
      A_VERSION_MAJOR = 0,
369
      A_VERSION_MINOR,
370
      A_HEADERS,
371
      A_METHOD,
372
      A_URL,
373
      A_STATUS_CODE,
374
      A_STATUS_MESSAGE,
375
      A_UPGRADE,
376
      A_SHOULD_KEEP_ALIVE,
377
      A_MAX
378
    };
379
380
176500
    Local<Value> argv[A_MAX];
381
17650
    Local<Object> obj = object();
382
17650
    Local<Value> cb = obj->Get(env()->context(),
383
35300
                               kOnHeadersComplete).ToLocalChecked();
384
385
17650
    if (!cb->IsFunction())
386
      return 0;
387
388
17650
    Local<Value> undefined = Undefined(env()->isolate());
389
176500
    for (size_t i = 0; i < arraysize(argv); i++)
390
158850
      argv[i] = undefined;
391
392
17650
    if (have_flushed_) {
393
      // Slow case, flush remaining headers.
394
16
      Flush();
395
    } else {
396
      // Fast case, pass headers and URL to JS land.
397
17634
      argv[A_HEADERS] = CreateHeaders();
398
17634
      if (parser_.type == HTTP_REQUEST)
399
28322
        argv[A_URL] = url_.ToString(env());
400
    }
401
402
17650
    num_fields_ = 0;
403
17650
    num_values_ = 0;
404
405
    // METHOD
406
17650
    if (parser_.type == HTTP_REQUEST) {
407
28338
      argv[A_METHOD] =
408
14169
          Uint32::NewFromUnsigned(env()->isolate(), parser_.method);
409
    }
410
411
    // STATUS
412
17650
    if (parser_.type == HTTP_RESPONSE) {
413
3481
      argv[A_STATUS_CODE] =
414
3481
          Integer::New(env()->isolate(), parser_.status_code);
415
6962
      argv[A_STATUS_MESSAGE] = status_message_.ToString(env());
416
    }
417
418
    // VERSION
419
17650
    argv[A_VERSION_MAJOR] = Integer::New(env()->isolate(), parser_.http_major);
420
17650
    argv[A_VERSION_MINOR] = Integer::New(env()->isolate(), parser_.http_minor);
421
422
    bool should_keep_alive;
423
17650
    should_keep_alive = llhttp_should_keep_alive(&parser_);
424
425
17650
    argv[A_SHOULD_KEEP_ALIVE] =
426
        Boolean::New(env()->isolate(), should_keep_alive);
427
428
35300
    argv[A_UPGRADE] = Boolean::New(env()->isolate(), parser_.upgrade);
429
430
    MaybeLocal<Value> head_response;
431
    {
432
      InternalCallbackScope callback_scope(
433
35298
          this, InternalCallbackScope::kSkipTaskQueues);
434
17650
      head_response = cb.As<Function>()->Call(
435
35300
          env()->context(), object(), arraysize(argv), argv);
436
17648
      if (head_response.IsEmpty()) callback_scope.MarkAsFailed();
437
    }
438
439
    int64_t val;
440
441
52928
    if (head_response.IsEmpty() || !head_response.ToLocalChecked()
442
35288
                                        ->IntegerValue(env()->context())
443
17640
                                        .To(&val)) {
444
8
      got_exception_ = true;
445
8
      return -1;
446
    }
447
448
17640
    return static_cast<int>(val);
449
  }
450
451
452
11469
  int on_body(const char* at, size_t length) {
453
11469
    if (length == 0)
454
      return 0;
455
456
11469
    Environment* env = this->env();
457
22938
    HandleScope handle_scope(env->isolate());
458
459
34407
    Local<Value> cb = object()->Get(env->context(), kOnBody).ToLocalChecked();
460
461
11469
    if (!cb->IsFunction())
462
      return 0;
463
464
11469
    Local<Value> buffer = Buffer::Copy(env, at, length).ToLocalChecked();
465
466
22938
    MaybeLocal<Value> r = MakeCallback(cb.As<Function>(), 1, &buffer);
467
468
11469
    if (r.IsEmpty()) {
469
      got_exception_ = true;
470
      llhttp_set_error_reason(&parser_, "HPE_JS_EXCEPTION:JS Exception");
471
      return HPE_USER;
472
    }
473
474
11469
    return 0;
475
  }
476
477
478
16440
  int on_message_complete() {
479
32880
    HandleScope scope(env()->isolate());
480
481
    // Important: Pop from the lists BEFORE resetting the last_message_start_
482
    // otherwise std::set.erase will fail.
483
16440
    if (connectionsList_ != nullptr) {
484
13984
      connectionsList_->Pop(this);
485
13984
      connectionsList_->PopActive(this);
486
    }
487
488
16440
    last_message_start_ = 0;
489
490
16440
    if (connectionsList_ != nullptr) {
491
13984
      connectionsList_->Push(this);
492
    }
493
494
16440
    if (num_fields_)
495
6
      Flush();  // Flush trailing HTTP headers.
496
497
16440
    Local<Object> obj = object();
498
16440
    Local<Value> cb = obj->Get(env()->context(),
499
32880
                               kOnMessageComplete).ToLocalChecked();
500
501
16440
    if (!cb->IsFunction())
502
2
      return 0;
503
504
    MaybeLocal<Value> r;
505
    {
506
      InternalCallbackScope callback_scope(
507
32876
          this, InternalCallbackScope::kSkipTaskQueues);
508
32876
      r = cb.As<Function>()->Call(env()->context(), object(), 0, nullptr);
509
16438
      if (r.IsEmpty()) callback_scope.MarkAsFailed();
510
    }
511
512
16438
    if (r.IsEmpty()) {
513
      got_exception_ = true;
514
      return -1;
515
    }
516
517
16438
    return 0;
518
  }
519
520
  // Reset nread for the next chunk
521
11654
  int on_chunk_header() {
522
11654
    header_nread_ = 0;
523
11654
    return 0;
524
  }
525
526
527
  // Reset nread for the next chunk
528
11500
  int on_chunk_complete() {
529
11500
    header_nread_ = 0;
530
11500
    return 0;
531
  }
532
533
5168
  static void New(const FunctionCallbackInfo<Value>& args) {
534
5168
    BindingData* binding_data = Environment::GetBindingData<BindingData>(args);
535
5168
    new Parser(binding_data, args.This());
536
5168
  }
537
538
539
3
  static void Close(const FunctionCallbackInfo<Value>& args) {
540
    Parser* parser;
541
3
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
542
543
3
    delete parser;
544
  }
545
546
547
6375
  static void Free(const FunctionCallbackInfo<Value>& args) {
548
    Parser* parser;
549
6375
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
550
551
6375
    if (parser->connectionsList_ != nullptr) {
552
2457
      parser->connectionsList_->Pop(parser);
553
2457
      parser->connectionsList_->PopActive(parser);
554
    }
555
556
    // Since the Parser destructor isn't going to run the destroy() callbacks
557
    // it needs to be triggered manually.
558
6375
    parser->EmitTraceEventDestroy();
559
6375
    parser->EmitDestroy();
560
  }
561
562
563
7777
  void Save() {
564
7777
    url_.Save();
565
7777
    status_message_.Save();
566
567
7965
    for (size_t i = 0; i < num_fields_; i++) {
568
188
      fields_[i].Save();
569
    }
570
571
7899
    for (size_t i = 0; i < num_values_; i++) {
572
122
      values_[i].Save();
573
    }
574
7777
  }
575
576
  // var bytesParsed = parser->execute(buffer);
577
3552
  static void Execute(const FunctionCallbackInfo<Value>& args) {
578
    Parser* parser;
579
3552
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
580
581
3552
    ArrayBufferViewContents<char> buffer(args[0]);
582
583
3552
    Local<Value> ret = parser->Execute(buffer.data(), buffer.length());
584
585
3551
    if (!ret.IsEmpty())
586
7096
      args.GetReturnValue().Set(ret);
587
  }
588
589
590
888
  static void Finish(const FunctionCallbackInfo<Value>& args) {
591
    Parser* parser;
592
888
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
593
594
888
    Local<Value> ret = parser->Execute(nullptr, 0);
595
596
888
    if (!ret.IsEmpty())
597
66
      args.GetReturnValue().Set(ret);
598
  }
599
600
601
6572
  static void Initialize(const FunctionCallbackInfo<Value>& args) {
602
6572
    Environment* env = Environment::GetCurrent(args);
603
604
6572
    uint64_t max_http_header_size = 0;
605
6572
    uint32_t lenient_flags = kLenientNone;
606
6572
    ConnectionsList* connectionsList = nullptr;
607
608
6572
    CHECK(args[0]->IsInt32());
609
6572
    CHECK(args[1]->IsObject());
610
611
6572
    if (args.Length() > 2) {
612
5402
      CHECK(args[2]->IsNumber());
613
5402
      max_http_header_size =
614
10804
          static_cast<uint64_t>(args[2].As<Number>()->Value());
615
    }
616
6572
    if (max_http_header_size == 0) {
617
6568
      max_http_header_size = env->options()->max_http_header_size;
618
    }
619
620
6572
    if (args.Length() > 3) {
621
5402
      CHECK(args[3]->IsInt32());
622
10804
      lenient_flags = args[3].As<Int32>()->Value();
623
    }
624
625

11520
    if (args.Length() > 4 && !args[4]->IsNullOrUndefined()) {
626
2472
      CHECK(args[4]->IsObject());
627
2472
      ASSIGN_OR_RETURN_UNWRAP(&connectionsList, args[4]);
628
    }
629
630
    llhttp_type_t type =
631
13144
        static_cast<llhttp_type_t>(args[0].As<Int32>()->Value());
632
633

6572
    CHECK(type == HTTP_REQUEST || type == HTTP_RESPONSE);
634
    Parser* parser;
635
6572
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
636
    // Should always be called from the same context.
637
6572
    CHECK_EQ(env, parser->env());
638
639
6572
    AsyncWrap::ProviderType provider =
640
6572
        (type == HTTP_REQUEST ?
641
            AsyncWrap::PROVIDER_HTTPINCOMINGMESSAGE
642
            : AsyncWrap::PROVIDER_HTTPCLIENTREQUEST);
643
644
6572
    parser->set_provider_type(provider);
645
19716
    parser->AsyncReset(args[1].As<Object>());
646
6572
    parser->Init(type, max_http_header_size, lenient_flags);
647
648
6572
    if (connectionsList != nullptr) {
649
2472
      parser->connectionsList_ = connectionsList;
650
651
      // This protects from a DoS attack where an attacker establishes
652
      // the connection without sending any data on applications where
653
      // server.timeout is left to the default value of zero.
654
2472
      parser->last_message_start_ = uv_hrtime();
655
656
      // Important: Push into the lists AFTER setting the last_message_start_
657
      // otherwise std::set.erase will fail later.
658
2472
      parser->connectionsList_->Push(parser);
659
2472
      parser->connectionsList_->PushActive(parser);
660
    } else {
661
4100
      parser->connectionsList_ = nullptr;
662
    }
663
  }
664
665
  template <bool should_pause>
666
22
  static void Pause(const FunctionCallbackInfo<Value>& args) {
667
22
    Environment* env = Environment::GetCurrent(args);
668
    Parser* parser;
669
22
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
670
    // Should always be called from the same context.
671
22
    CHECK_EQ(env, parser->env());
672
673
    if (should_pause) {
674
8
      llhttp_pause(&parser->parser_);
675
    } else {
676
14
      llhttp_resume(&parser->parser_);
677
    }
678
  }
679
680
681
3465
  static void Consume(const FunctionCallbackInfo<Value>& args) {
682
    Parser* parser;
683
3465
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
684
3465
    CHECK(args[0]->IsObject());
685
6930
    StreamBase* stream = StreamBase::FromObject(args[0].As<Object>());
686
3465
    CHECK_NOT_NULL(stream);
687
3465
    stream->PushStreamListener(parser);
688
  }
689
690
691
3455
  static void Unconsume(const FunctionCallbackInfo<Value>& args) {
692
    Parser* parser;
693
3455
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
694
695
    // Already unconsumed
696
3455
    if (parser->stream_ == nullptr)
697
      return;
698
699
3455
    parser->stream_->RemoveStreamListener(parser);
700
  }
701
702
703
38
  static void GetCurrentBuffer(const FunctionCallbackInfo<Value>& args) {
704
    Parser* parser;
705
38
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
706
707
38
    Local<Object> ret = Buffer::Copy(
708
        parser->env(),
709
        parser->current_buffer_data_,
710
76
        parser->current_buffer_len_).ToLocalChecked();
711
712
76
    args.GetReturnValue().Set(ret);
713
  }
714
715
  static void Duration(const FunctionCallbackInfo<Value>& args) {
716
    Parser* parser;
717
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
718
719
    if (parser->last_message_start_ == 0) {
720
      args.GetReturnValue().Set(0);
721
      return;
722
    }
723
724
    double duration = (uv_hrtime() - parser->last_message_start_) / 1e6;
725
    args.GetReturnValue().Set(duration);
726
  }
727
728
  static void HeadersCompleted(const FunctionCallbackInfo<Value>& args) {
729
    Parser* parser;
730
    ASSIGN_OR_RETURN_UNWRAP(&parser, args.Holder());
731
732
    args.GetReturnValue().Set(parser->headers_completed_);
733
  }
734
735
 protected:
736
  static const size_t kAllocBufferSize = 64 * 1024;
737
738
4492
  uv_buf_t OnStreamAlloc(size_t suggested_size) override {
739
    // For most types of streams, OnStreamRead will be immediately after
740
    // OnStreamAlloc, and will consume all data, so using a static buffer for
741
    // reading is more efficient. For other streams, just use Malloc() directly.
742
4492
    if (binding_data_->parser_buffer_in_use)
743
      return uv_buf_init(Malloc(suggested_size), suggested_size);
744
4492
    binding_data_->parser_buffer_in_use = true;
745
746
4492
    if (binding_data_->parser_buffer.empty())
747
358
      binding_data_->parser_buffer.resize(kAllocBufferSize);
748
749
4492
    return uv_buf_init(binding_data_->parser_buffer.data(), kAllocBufferSize);
750
  }
751
752
753
4533
  void OnStreamRead(ssize_t nread, const uv_buf_t& buf) override {
754
4533
    HandleScope scope(env()->isolate());
755
    // Once we’re done here, either indicate that the HTTP parser buffer
756
    // is free for re-use, or free() the data if it didn’t come from there
757
    // in the first place.
758
4529
    auto on_scope_leave = OnScopeLeave([&]() {
759
4529
      if (buf.base == binding_data_->parser_buffer.data())
760
4490
        binding_data_->parser_buffer_in_use = false;
761
      else
762
39
        free(buf.base);
763
4533
    });
764
765
4533
    if (nread < 0) {
766
306
      PassReadErrorToPreviousListener(nread);
767
306
      return;
768
    }
769
770
    // Ignore, empty reads have special meaning in http parser
771
4227
    if (nread == 0)
772
      return;
773
774
4227
    Local<Value> ret = Execute(buf.base, nread);
775
776
    // Exception
777
4226
    if (ret.IsEmpty())
778
5
      return;
779
780
    Local<Value> cb =
781
12663
        object()->Get(env()->context(), kOnExecute).ToLocalChecked();
782
783
4221
    if (!cb->IsFunction())
784
1003
      return;
785
786
    // Hooks for GetCurrentBuffer
787
3218
    current_buffer_len_ = nread;
788
3218
    current_buffer_data_ = buf.base;
789
790
6436
    MakeCallback(cb.As<Function>(), 1, &ret);
791
792
3215
    current_buffer_len_ = 0;
793
3215
    current_buffer_data_ = nullptr;
794
  }
795
796
797
8667
  Local<Value> Execute(const char* data, size_t len) {
798
8667
    EscapableHandleScope scope(env()->isolate());
799
800
8667
    current_buffer_len_ = len;
801
8667
    current_buffer_data_ = data;
802
8667
    got_exception_ = false;
803
804
    llhttp_errno_t err;
805
806
8667
    if (data == nullptr) {
807
888
      err = llhttp_finish(&parser_);
808
    } else {
809
7779
      err = llhttp_execute(&parser_, data, len);
810
7777
      Save();
811
    }
812
813
    // Calculate bytes read and resume after Upgrade/CONNECT pause
814
8665
    size_t nread = len;
815
8665
    if (err != HPE_OK) {
816
436
      nread = llhttp_get_error_pos(&parser_) - data;
817
818
      // This isn't a real pause, just a way to stop parsing early.
819
436
      if (err == HPE_PAUSED_UPGRADE) {
820
100
        err = HPE_OK;
821
100
        llhttp_resume_after_upgrade(&parser_);
822
      }
823
    }
824
825
    // Apply pending pause
826
8665
    if (pending_pause_) {
827
      pending_pause_ = false;
828
      llhttp_pause(&parser_);
829
    }
830
831
8665
    current_buffer_len_ = 0;
832
8665
    current_buffer_data_ = nullptr;
833
834
    // If there was an exception in one of the callbacks
835
8665
    if (got_exception_)
836
8
      return scope.Escape(Local<Value>());
837
838
8657
    Local<Integer> nread_obj = Integer::New(env()->isolate(), nread);
839
840
    // If there was a parse error in one of the callbacks
841
    // TODO(bnoordhuis) What if there is an error on EOF?
842

8657
    if (!parser_.upgrade && err != HPE_OK) {
843
228
      Local<Value> e = Exception::Error(env()->parse_error_string());
844
228
      Local<Object> obj = e->ToObject(env()->isolate()->GetCurrentContext())
845
228
        .ToLocalChecked();
846
228
      obj->Set(env()->context(),
847
               env()->bytes_parsed_string(),
848
456
               nread_obj).Check();
849
228
      const char* errno_reason = llhttp_get_error_reason(&parser_);
850
851
      Local<String> code;
852
      Local<String> reason;
853
228
      if (err == HPE_USER) {
854
19
        const char* colon = strchr(errno_reason, ':');
855
19
        CHECK_NOT_NULL(colon);
856
        code = OneByteString(env()->isolate(),
857
                             errno_reason,
858
19
                             static_cast<int>(colon - errno_reason));
859
19
        reason = OneByteString(env()->isolate(), colon + 1);
860
      } else {
861
209
        code = OneByteString(env()->isolate(), llhttp_errno_name(err));
862
209
        reason = OneByteString(env()->isolate(), errno_reason);
863
      }
864
865
684
      obj->Set(env()->context(), env()->code_string(), code).Check();
866
684
      obj->Set(env()->context(), env()->reason_string(), reason).Check();
867
228
      return scope.Escape(e);
868
    }
869
870
    // No return value is needed for `Finish()`
871
8429
    if (data == nullptr) {
872
855
      return scope.Escape(Local<Value>());
873
    }
874
7574
    return scope.Escape(nread_obj);
875
  }
876
877
17703
  Local<Array> CreateHeaders() {
878
    // There could be extra entries but the max size should be fixed
879
1150695
    Local<Value> headers_v[kMaxHeaderFieldsCount * 2];
880
881
36557
    for (size_t i = 0; i < num_values_; ++i) {
882
18854
      headers_v[i * 2] = fields_[i].ToString(env());
883
37708
      headers_v[i * 2 + 1] = values_[i].ToTrimmedString(env());
884
    }
885
886
17703
    return Array::New(env()->isolate(), headers_v, num_values_ * 2);
887
  }
888
889
890
  // spill headers and request path to JS land
891
69
  void Flush() {
892
69
    HandleScope scope(env()->isolate());
893
894
69
    Local<Object> obj = object();
895
138
    Local<Value> cb = obj->Get(env()->context(), kOnHeaders).ToLocalChecked();
896
897
69
    if (!cb->IsFunction())
898
      return;
899
900
    Local<Value> argv[2] = {
901
      CreateHeaders(),
902
      url_.ToString(env())
903
138
    };
904
905
    MaybeLocal<Value> r = MakeCallback(cb.As<Function>(),
906
69
                                       arraysize(argv),
907
138
                                       argv);
908
909
69
    if (r.IsEmpty())
910
      got_exception_ = true;
911
912
69
    url_.Reset();
913
69
    have_flushed_ = true;
914
  }
915
916
917
6572
  void Init(llhttp_type_t type, uint64_t max_http_header_size,
918
            uint32_t lenient_flags) {
919
6572
    llhttp_init(&parser_, type, &settings);
920
921
6572
    if (lenient_flags & kLenientHeaders) {
922
5
      llhttp_set_lenient_headers(&parser_, 1);
923
    }
924
6572
    if (lenient_flags & kLenientChunkedLength) {
925
5
      llhttp_set_lenient_chunked_length(&parser_, 1);
926
    }
927
6572
    if (lenient_flags & kLenientKeepAlive) {
928
5
      llhttp_set_lenient_keep_alive(&parser_, 1);
929
    }
930
931
6572
    header_nread_ = 0;
932
6572
    url_.Reset();
933
6572
    status_message_.Reset();
934
6572
    num_fields_ = 0;
935
6572
    num_values_ = 0;
936
6572
    have_flushed_ = false;
937
6572
    got_exception_ = false;
938
6572
    headers_completed_ = false;
939
6572
    max_http_header_size_ = max_http_header_size;
940
6572
  }
941
942
943
55588
  int TrackHeader(size_t len) {
944
55588
    header_nread_ += len;
945
55588
    if (header_nread_ >= max_http_header_size_) {
946
17
      llhttp_set_error_reason(&parser_, "HPE_HEADER_OVERFLOW:Header overflow");
947
17
      return HPE_USER;
948
    }
949
55571
    return 0;
950
  }
951
952
953
141870
  int MaybePause() {
954
141870
    if (!pending_pause_) {
955
141870
      return 0;
956
    }
957
958
    pending_pause_ = false;
959
    llhttp_set_error_reason(&parser_, "Paused in callback");
960
    return HPE_PAUSED;
961
  }
962
963
964
  bool IsNotIndicativeOfMemoryLeakAtExit() const override {
965
    // HTTP parsers are able to emit events without any GC root referring
966
    // to them, because they receive events directly from the underlying
967
    // libuv resource.
968
    return true;
969
  }
970
971
972
  llhttp_t parser_;
973
  StringPtr fields_[kMaxHeaderFieldsCount];  // header fields
974
  StringPtr values_[kMaxHeaderFieldsCount];  // header values
975
  StringPtr url_;
976
  StringPtr status_message_;
977
  size_t num_fields_;
978
  size_t num_values_;
979
  bool have_flushed_;
980
  bool got_exception_;
981
  size_t current_buffer_len_;
982
  const char* current_buffer_data_;
983
  bool headers_completed_ = false;
984
  bool pending_pause_ = false;
985
  uint64_t header_nread_ = 0;
986
  uint64_t max_http_header_size_;
987
  uint64_t last_message_start_;
988
  ConnectionsList* connectionsList_;
989
990
  BaseObjectPtr<BindingData> binding_data_;
991
992
  // These are helper functions for filling `http_parser_settings`, which turn
993
  // a member function of Parser into a C-style HTTP parser callback.
994
  template <typename Parser, Parser> struct Proxy;
995
  template <typename Parser, typename ...Args, int (Parser::*Member)(Args...)>
996
  struct Proxy<int (Parser::*)(Args...), Member> {
997
284014
    static int Raw(llhttp_t* p, Args ... args) {
998
284014
      Parser* parser = ContainerOf(&Parser::parser_, p);
999
284014
      int rv = (parser->*Member)(std::forward<Args>(args)...);
1000
284010
      if (rv == 0) {
1001
283740
        rv = parser->MaybePause();
1002
      }
1003
284010
      return rv;
1004
    }
1005
  };
1006
1007
  typedef int (Parser::*Call)();
1008
  typedef int (Parser::*DataCall)(const char* at, size_t length);
1009
1010
  static const llhttp_settings_t settings;
1011
};
1012
1013
274253
bool ParserComparator::operator()(const Parser* lhs, const Parser* rhs) const {
1014

274253
  if (lhs->last_message_start_ == 0 && rhs->last_message_start_ == 0) {
1015
    // When both parsers are idle, guarantee strict order by
1016
    // comparing pointers as ints.
1017
56163
    return lhs < rhs;
1018
218090
  } else if (lhs->last_message_start_ == 0) {
1019
21708
    return true;
1020
196382
  } else if (rhs->last_message_start_ == 0) {
1021
7507
    return false;
1022
  }
1023
1024
188875
  return lhs->last_message_start_ < rhs->last_message_start_;
1025
}
1026
1027
564
void ConnectionsList::New(const FunctionCallbackInfo<Value>& args) {
1028
564
  Local<Context> context = args.GetIsolate()->GetCurrentContext();
1029
564
  Environment* env = Environment::GetCurrent(context);
1030
1031
564
  new ConnectionsList(env, args.This());
1032
564
}
1033
1034
4
void ConnectionsList::All(const FunctionCallbackInfo<Value>& args) {
1035
4
  Isolate* isolate = args.GetIsolate();
1036
4
  Local<Context> context = isolate->GetCurrentContext();
1037
1038
4
  Local<Array> all = Array::New(isolate);
1039
  ConnectionsList* list;
1040
1041
4
  ASSIGN_OR_RETURN_UNWRAP(&list, args.Holder());
1042
1043
4
  uint32_t i = 0;
1044
10
  for (auto parser : list->all_connections_) {
1045
18
    if (all->Set(context, i++, parser->object()).IsNothing()) {
1046
      return;
1047
    }
1048
  }
1049
1050
8
  return args.GetReturnValue().Set(all);
1051
}
1052
1053
2
void ConnectionsList::Idle(const FunctionCallbackInfo<Value>& args) {
1054
2
  Isolate* isolate = args.GetIsolate();
1055
2
  Local<Context> context = isolate->GetCurrentContext();
1056
1057
2
  Local<Array> idle = Array::New(isolate);
1058
  ConnectionsList* list;
1059
1060
2
  ASSIGN_OR_RETURN_UNWRAP(&list, args.Holder());
1061
1062
2
  uint32_t i = 0;
1063
6
  for (auto parser : list->all_connections_) {
1064
4
    if (parser->last_message_start_ == 0) {
1065
6
      if (idle->Set(context, i++, parser->object()).IsNothing()) {
1066
        return;
1067
      }
1068
    }
1069
  }
1070
1071
4
  return args.GetReturnValue().Set(idle);
1072
}
1073
1074
void ConnectionsList::Active(const FunctionCallbackInfo<Value>& args) {
1075
  Isolate* isolate = args.GetIsolate();
1076
  Local<Context> context = isolate->GetCurrentContext();
1077
1078
  Local<Array> active = Array::New(isolate);
1079
  ConnectionsList* list;
1080
1081
  ASSIGN_OR_RETURN_UNWRAP(&list, args.Holder());
1082
1083
  uint32_t i = 0;
1084
  for (auto parser : list->active_connections_) {
1085
    if (active->Set(context, i++, parser->object()).IsNothing()) {
1086
      return;
1087
    }
1088
  }
1089
1090
  return args.GetReturnValue().Set(active);
1091
}
1092
1093
85
void ConnectionsList::Expired(const FunctionCallbackInfo<Value>& args) {
1094
85
  Isolate* isolate = args.GetIsolate();
1095
85
  Local<Context> context = isolate->GetCurrentContext();
1096
1097
85
  Local<Array> expired = Array::New(isolate);
1098
  ConnectionsList* list;
1099
1100
85
  ASSIGN_OR_RETURN_UNWRAP(&list, args.Holder());
1101
85
  CHECK(args[0]->IsNumber());
1102
85
  CHECK(args[1]->IsNumber());
1103
  uint64_t headers_timeout =
1104
170
    static_cast<uint64_t>(args[0].As<Uint32>()->Value()) * 1000000;
1105
  uint64_t request_timeout =
1106
170
    static_cast<uint64_t>(args[1].As<Uint32>()->Value()) * 1000000;
1107
1108

85
  if (headers_timeout == 0 && request_timeout == 0) {
1109
    return args.GetReturnValue().Set(expired);
1110

85
  } else if (request_timeout > 0 && headers_timeout > request_timeout) {
1111
    std::swap(headers_timeout, request_timeout);
1112
  }
1113
1114
85
  const uint64_t now = uv_hrtime();
1115
85
  const uint64_t headers_deadline =
1116
85
    headers_timeout > 0 ? now - headers_timeout : 0;
1117
85
  const uint64_t request_deadline =
1118
85
    request_timeout > 0 ? now - request_timeout : 0;
1119
1120
85
  uint32_t i = 0;
1121
85
  auto iter = list->active_connections_.begin();
1122
85
  auto end = list->active_connections_.end();
1123
167
  while (iter != end) {
1124
82
    Parser* parser = *iter;
1125
82
    iter++;
1126
1127
    // Check for expiration.
1128
82
    if (
1129

82
      (!parser->headers_completed_ && headers_deadline > 0 &&
1130

82
        parser->last_message_start_ < headers_deadline) ||
1131
      (
1132
60
        request_deadline > 0 &&
1133
60
        parser->last_message_start_ < request_deadline)
1134
    ) {
1135
39
      if (expired->Set(context, i++, parser->object()).IsNothing()) {
1136
        return;
1137
      }
1138
1139
13
      list->active_connections_.erase(parser);
1140
    }
1141
  }
1142
1143
170
  return args.GetReturnValue().Set(expired);
1144
}
1145
1146
const llhttp_settings_t Parser::settings = {
1147
  Proxy<Call, &Parser::on_message_begin>::Raw,
1148
  Proxy<DataCall, &Parser::on_url>::Raw,
1149
  Proxy<DataCall, &Parser::on_status>::Raw,
1150
  Proxy<DataCall, &Parser::on_header_field>::Raw,
1151
  Proxy<DataCall, &Parser::on_header_value>::Raw,
1152
  Proxy<Call, &Parser::on_headers_complete>::Raw,
1153
  Proxy<DataCall, &Parser::on_body>::Raw,
1154
  Proxy<Call, &Parser::on_message_complete>::Raw,
1155
  Proxy<Call, &Parser::on_chunk_header>::Raw,
1156
  Proxy<Call, &Parser::on_chunk_complete>::Raw,
1157
1158
  // on_url_complete
1159
  nullptr,
1160
  // on_status_complete
1161
  nullptr,
1162
  // on_header_field_complete
1163
  nullptr,
1164
  // on_header_value_complete
1165
  nullptr,
1166
};
1167
1168
1169
1050
void InitializeHttpParser(Local<Object> target,
1170
                          Local<Value> unused,
1171
                          Local<Context> context,
1172
                          void* priv) {
1173
1050
  Environment* env = Environment::GetCurrent(context);
1174
  BindingData* const binding_data =
1175
1050
      env->AddBindingData<BindingData>(context, target);
1176
1050
  if (binding_data == nullptr) return;
1177
1178
1050
  Local<FunctionTemplate> t = env->NewFunctionTemplate(Parser::New);
1179
2100
  t->InstanceTemplate()->SetInternalFieldCount(Parser::kInternalFieldCount);
1180
1181
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "REQUEST"),
1182
         Integer::New(env->isolate(), HTTP_REQUEST));
1183
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "RESPONSE"),
1184
         Integer::New(env->isolate(), HTTP_RESPONSE));
1185
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnMessageBegin"),
1186
         Integer::NewFromUnsigned(env->isolate(), kOnMessageBegin));
1187
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnHeaders"),
1188
         Integer::NewFromUnsigned(env->isolate(), kOnHeaders));
1189
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnHeadersComplete"),
1190
         Integer::NewFromUnsigned(env->isolate(), kOnHeadersComplete));
1191
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnBody"),
1192
         Integer::NewFromUnsigned(env->isolate(), kOnBody));
1193
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnMessageComplete"),
1194
         Integer::NewFromUnsigned(env->isolate(), kOnMessageComplete));
1195
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnExecute"),
1196
         Integer::NewFromUnsigned(env->isolate(), kOnExecute));
1197
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnTimeout"),
1198
         Integer::NewFromUnsigned(env->isolate(), kOnTimeout));
1199
1200
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientNone"),
1201
         Integer::NewFromUnsigned(env->isolate(), kLenientNone));
1202
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientHeaders"),
1203
         Integer::NewFromUnsigned(env->isolate(), kLenientHeaders));
1204
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientChunkedLength"),
1205
         Integer::NewFromUnsigned(env->isolate(), kLenientChunkedLength));
1206
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientKeepAlive"),
1207
         Integer::NewFromUnsigned(env->isolate(), kLenientKeepAlive));
1208
3150
  t->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kLenientAll"),
1209
         Integer::NewFromUnsigned(env->isolate(), kLenientAll));
1210
1211
1050
  Local<Array> methods = Array::New(env->isolate());
1212
#define V(num, name, string)                                                  \
1213
    methods->Set(env->context(),                                              \
1214
        num, FIXED_ONE_BYTE_STRING(env->isolate(), #string)).Check();
1215
72450
  HTTP_METHOD_MAP(V)
1216
#undef V
1217
1050
  target->Set(env->context(),
1218
              FIXED_ONE_BYTE_STRING(env->isolate(), "methods"),
1219
3150
              methods).Check();
1220
1221
1050
  t->Inherit(AsyncWrap::GetConstructorTemplate(env));
1222
1050
  env->SetProtoMethod(t, "close", Parser::Close);
1223
1050
  env->SetProtoMethod(t, "free", Parser::Free);
1224
1050
  env->SetProtoMethod(t, "execute", Parser::Execute);
1225
1050
  env->SetProtoMethod(t, "finish", Parser::Finish);
1226
1050
  env->SetProtoMethod(t, "initialize", Parser::Initialize);
1227
1050
  env->SetProtoMethod(t, "pause", Parser::Pause<true>);
1228
1050
  env->SetProtoMethod(t, "resume", Parser::Pause<false>);
1229
1050
  env->SetProtoMethod(t, "consume", Parser::Consume);
1230
1050
  env->SetProtoMethod(t, "unconsume", Parser::Unconsume);
1231
1050
  env->SetProtoMethod(t, "getCurrentBuffer", Parser::GetCurrentBuffer);
1232
1050
  env->SetProtoMethod(t, "duration", Parser::Duration);
1233
1050
  env->SetProtoMethod(t, "headersCompleted", Parser::HeadersCompleted);
1234
1235
1050
  env->SetConstructorFunction(target, "HTTPParser", t);
1236
1237
1050
  Local<FunctionTemplate> c = env->NewFunctionTemplate(ConnectionsList::New);
1238
1050
  c->InstanceTemplate()
1239
1050
    ->SetInternalFieldCount(ConnectionsList::kInternalFieldCount);
1240
1050
  env->SetProtoMethod(c, "all", ConnectionsList::All);
1241
1050
  env->SetProtoMethod(c, "idle", ConnectionsList::Idle);
1242
1050
  env->SetProtoMethod(c, "active", ConnectionsList::Active);
1243
1050
  env->SetProtoMethod(c, "expired", ConnectionsList::Expired);
1244
1050
  env->SetConstructorFunction(target, "ConnectionsList", c);
1245
}
1246
1247
}  // anonymous namespace
1248
}  // namespace node
1249
1250
5201
NODE_MODULE_CONTEXT_AWARE_INTERNAL(http_parser, node::InitializeHttpParser)