Skip to content

Commit 482e23f

Browse files
committed
child_process: allow 'http_parser' monkey patching again
Lazy load _http_common and HTTPParser so that the 'http_parser' binding can be monkey patched before any internal modules require it. This also probably improves startup performance minimally for programs that never require the HTTP stack. Fixes: nodejs#23716 Fixes: creationix/http-parser-js#57
1 parent c515e5c commit 482e23f

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/internal/child_process.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ const { owner_symbol } = require('internal/async_hooks').symbols;
3838
const { convertToValidSignal } = require('internal/util');
3939
const { isArrayBufferView } = require('internal/util/types');
4040
const spawn_sync = internalBinding('spawn_sync');
41-
const { HTTPParser } = internalBinding('http_parser');
42-
const { freeParser } = require('_http_common');
4341
const { kStateSymbol } = require('internal/dgram');
4442

4543
const {
@@ -57,6 +55,10 @@ const { SocketListSend, SocketListReceive } = SocketList;
5755

5856
// Lazy loaded for startup performance.
5957
let StringDecoder;
58+
// Lazy loaded for startup performance and to allow monkey patching of
59+
// internalBinding('http_parser').HTTPParser.
60+
let freeParser;
61+
let HTTPParser;
6062

6163
const MAX_HANDLE_RETRANSMISSIONS = 3;
6264

@@ -121,6 +123,12 @@ const handleConversion = {
121123
handle.onread = nop;
122124
socket._handle = null;
123125
socket.setTimeout(0);
126+
127+
if (freeParser === undefined)
128+
freeParser = require('_http_common').freeParser;
129+
if (HTTPParser === undefined)
130+
HTTPParser = internalBinding('http_parser').HTTPParser;
131+
124132
// In case of an HTTP connection socket, release the associated
125133
// resources
126134
if (socket.parser && socket.parser instanceof HTTPParser) {

0 commit comments

Comments
 (0)