• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const assert = require('assert');
5const tick = require('../common/tick');
6const initHooks = require('./init-hooks');
7const { checkInvocations } = require('./hook-checks');
8
9const hooks = initHooks();
10hooks.enable();
11
12const { HTTPParser } = require('_http_common');
13
14const REQUEST = HTTPParser.REQUEST;
15
16const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
17
18const request = Buffer.from(
19  'GET /hello HTTP/1.1\r\n\r\n',
20);
21
22const parser = new HTTPParser();
23parser.initialize(REQUEST, {});
24const as = hooks.activitiesOfTypes('HTTPINCOMINGMESSAGE');
25const httpparser = as[0];
26
27assert.strictEqual(as.length, 1);
28assert.strictEqual(typeof httpparser.uid, 'number');
29assert.strictEqual(typeof httpparser.triggerAsyncId, 'number');
30checkInvocations(httpparser, { init: 1 }, 'when created new Httphttpparser');
31
32parser[kOnHeadersComplete] = common.mustCall(onheadersComplete);
33parser.execute(request, 0, request.length);
34
35function onheadersComplete() {
36  checkInvocations(httpparser, { init: 1, before: 1 },
37                   'when onheadersComplete called');
38  tick(1, common.mustCall(tick1));
39}
40
41function tick1() {
42  parser.close();
43  tick(1);
44}
45
46process.on('exit', onexit);
47
48function onexit() {
49  hooks.disable();
50  hooks.sanityCheck('HTTPINCOMINGMESSAGE');
51  checkInvocations(httpparser, { init: 1, before: 1, after: 1, destroy: 1 },
52                   'when process exits');
53}
54