Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 54635f5

Browse files
JimblyMylesBorins
authored andcommittedJan 8, 2020
http: fix monkey-patching of http_parser
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 <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 008ac37 commit 54635f5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed
 

‎lib/internal/bootstrap/loaders.js

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const internalBindingWhitelist = new SafeSet([
7575
'fs',
7676
'fs_event_wrap',
7777
'http_parser',
78+
'http_parser_llhttp',
7879
'icu',
7980
'inspector',
8081
'js_stream',

‎test/parallel/test-http-parser-lazy-loaded.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
'use strict';
44
const common = require('../common');
5-
const { internalBinding } = require('internal/test/binding');
65
const { getOptionValue } = require('internal/options');
76

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

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

2426
const assert = require('assert');
@@ -34,7 +36,9 @@ assert.strictEqual(parser.test_type, DummyParser.REQUEST);
3436
if (process.argv[2] !== 'child') {
3537
// Also test in a child process with IPC (specific case of https://github.com/nodejs/node/issues/23716)
3638
const child = spawn(process.execPath, [
37-
'--expose-internals', __filename, 'child'
39+
'--expose-internals',
40+
`--http-parser=${getOptionValue('--http-parser')}`,
41+
__filename, 'child'
3842
], {
3943
stdio: ['inherit', 'inherit', 'inherit', 'ipc']
4044
});

0 commit comments

Comments
 (0)
Please sign in to comment.