From 54635f583730b37c1dd5fd89207a4b33b01d8b73 Mon Sep 17 00:00:00 2001 From: Jimb Esser Date: Sat, 2 Nov 2019 10:10:48 -0700 Subject: [PATCH] http: fix monkey-patching of http_parser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/creationix/http-parser-js/issues/65 PR-URL: https://github.com/nodejs/node/pull/30222 Reviewed-By: Anna Henningsen Reviewed-By: Michaƫl Zasso --- lib/internal/bootstrap/loaders.js | 1 + test/parallel/test-http-parser-lazy-loaded.js | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/internal/bootstrap/loaders.js b/lib/internal/bootstrap/loaders.js index 0cad5209c4ff4e..649f4843a846fa 100644 --- a/lib/internal/bootstrap/loaders.js +++ b/lib/internal/bootstrap/loaders.js @@ -75,6 +75,7 @@ const internalBindingWhitelist = new SafeSet([ 'fs', 'fs_event_wrap', 'http_parser', + 'http_parser_llhttp', 'icu', 'inspector', 'js_stream', diff --git a/test/parallel/test-http-parser-lazy-loaded.js b/test/parallel/test-http-parser-lazy-loaded.js index a6c19f9353ad50..5fc376951027ab 100644 --- a/test/parallel/test-http-parser-lazy-loaded.js +++ b/test/parallel/test-http-parser-lazy-loaded.js @@ -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 @@ -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'); @@ -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'] });