Skip to content

Commit

Permalink
http: fix monkey-patching of http_parser
Browse files Browse the repository at this point in the history
Fixes inability to monkey-patch the HTTP Parser on Node v12.x.
This is not an issue on Node v13+ since the parser was renamed
back to the old (already monkey-patchable) `http_parser` name,
however the test in master could also use updating.

Fixes: creationix/http-parser-js#65

PR-URL: #30222
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
Jimbly authored and BethGriggs committed Feb 6, 2020
1 parent 8d336ff commit 2445bc0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit 2445bc0

Please sign in to comment.