Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v12.x] http: fix monkey-patching of http_parser #30222

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/internal/bootstrap/loaders.js
Expand Up @@ -75,6 +75,7 @@ const internalBindingWhitelist = new SafeSet([
'fs',
'fs_event_wrap',
'http_parser',
'http_parser_llhttp',
'icu',
'inspector',
'js_stream',
Expand Down
10 changes: 7 additions & 3 deletions test/parallel/test-http-parser-lazy-loaded.js
Expand Up @@ -2,7 +2,6 @@

'use strict';
const common = require('../common');
const { internalBinding } = require('internal/test/binding');
const { getOptionValue } = require('internal/options');

// Monkey patch before requiring anything
Expand All @@ -16,9 +15,12 @@ class DummyParser {
}
DummyParser.REQUEST = Symbol();

// Note: using process.binding instead of internalBinding because this test is
// verifying that user applications are still able to monkey-patch the
// http_parser module.
const binding =
getOptionValue('--http-parser') === 'legacy' ?
internalBinding('http_parser') : internalBinding('http_parser_llhttp');
process.binding('http_parser') : process.binding('http_parser_llhttp');
binding.HTTPParser = DummyParser;

const assert = require('assert');
Expand All @@ -34,7 +36,9 @@ 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'
'--expose-internals',
`--http-parser=${getOptionValue('--http-parser')}`,
__filename, 'child'
], {
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
});
Expand Down