node/test/parallel/test-http-parser-lazy-loaded.js
Anna Henningsen ac59dc42ed
http: remove legacy parser
Remove the legacy `http_parser` implementation as a dependency
and all code that uses it in favor of llhttp, given that the latter
has been the default for all of Node 12 with no outstanding issues.

PR-URL: https://github.com/nodejs/node/pull/29589
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
2019-09-20 20:18:35 +02:00

43 lines
1.2 KiB
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
const { internalBinding } = require('internal/test/binding');
// Monkey patch before requiring anything
class DummyParser {
constructor() {
this.test_type = null;
}
initialize(type) {
this.test_type = type;
}
}
DummyParser.REQUEST = Symbol();
const binding = internalBinding('http_parser');
binding.HTTPParser = DummyParser;
const assert = require('assert');
const { spawn } = require('child_process');
const { parsers } = require('_http_common');
// Test _http_common was not loaded before monkey patching
const parser = parsers.alloc();
parser.initialize(DummyParser.REQUEST, {});
assert.strictEqual(parser instanceof DummyParser, true);
assert.strictEqual(parser.test_type, DummyParser.REQUEST);
if (process.argv[2] !== 'child') {
// Also test in a child process with IPC (specific case of https://github.com/nodejs/node/issues/23716)
const child = spawn(process.execPath, [
'--expose-internals', __filename, 'child'
], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
child.on('exit', common.mustCall((code, signal) => {
assert.strictEqual(code, 0);
assert.strictEqual(signal, null);
}));
}