2016-11-23 00:13:44 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
2018-10-13 01:35:08 +08:00
|
|
|
const tick = require('../common/tick');
|
2016-11-23 00:13:44 +08:00
|
|
|
const initHooks = require('./init-hooks');
|
|
|
|
const { checkInvocations } = require('./hook-checks');
|
|
|
|
|
2018-08-15 08:01:06 +08:00
|
|
|
const hooks = initHooks();
|
|
|
|
hooks.enable();
|
|
|
|
|
2018-11-30 14:39:02 +08:00
|
|
|
const { HTTPParser } = require('_http_common');
|
2016-11-23 00:13:44 +08:00
|
|
|
|
|
|
|
const REQUEST = HTTPParser.REQUEST;
|
|
|
|
|
|
|
|
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
|
|
|
|
|
|
|
|
const request = Buffer.from(
|
2022-11-22 01:43:47 +08:00
|
|
|
'GET /hello HTTP/1.1\r\n\r\n',
|
2016-11-23 00:13:44 +08:00
|
|
|
);
|
|
|
|
|
2019-04-23 06:57:12 +08:00
|
|
|
const parser = new HTTPParser();
|
|
|
|
parser.initialize(REQUEST, {});
|
2018-12-14 01:35:48 +08:00
|
|
|
const as = hooks.activitiesOfTypes('HTTPINCOMINGMESSAGE');
|
2016-11-23 00:13:44 +08:00
|
|
|
const httpparser = as[0];
|
|
|
|
|
2017-05-26 23:53:06 +08:00
|
|
|
assert.strictEqual(as.length, 1);
|
|
|
|
assert.strictEqual(typeof httpparser.uid, 'number');
|
2017-06-14 18:39:53 +08:00
|
|
|
assert.strictEqual(typeof httpparser.triggerAsyncId, 'number');
|
2016-11-23 00:13:44 +08:00
|
|
|
checkInvocations(httpparser, { init: 1 }, 'when created new Httphttpparser');
|
|
|
|
|
|
|
|
parser[kOnHeadersComplete] = common.mustCall(onheadersComplete);
|
|
|
|
parser.execute(request, 0, request.length);
|
|
|
|
|
|
|
|
function onheadersComplete() {
|
|
|
|
checkInvocations(httpparser, { init: 1, before: 1 },
|
|
|
|
'when onheadersComplete called');
|
|
|
|
tick(1, common.mustCall(tick1));
|
|
|
|
}
|
|
|
|
|
|
|
|
function tick1() {
|
|
|
|
parser.close();
|
|
|
|
tick(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
process.on('exit', onexit);
|
|
|
|
|
|
|
|
function onexit() {
|
|
|
|
hooks.disable();
|
2018-12-14 01:35:48 +08:00
|
|
|
hooks.sanityCheck('HTTPINCOMINGMESSAGE');
|
2016-11-23 00:13:44 +08:00
|
|
|
checkInvocations(httpparser, { init: 1, before: 1, after: 1, destroy: 1 },
|
|
|
|
'when process exits');
|
|
|
|
}
|