diff options
author | Jimb Esser <wasteland@gmail.com> | 2018-10-31 22:55:00 +0300 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2018-11-09 01:38:23 +0300 |
commit | 7d86a5324bc29c21afce8cba3dba508b78d48cd5 (patch) | |
tree | e52982270b7712f847eef6c88fa05d865d3b70a9 /lib/internal/child_process.js | |
parent | 1f6c4ba61d70318d1422a0dac2297f519ee35045 (diff) |
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: https://github.com/nodejs/node/issues/23716
Fixes: https://github.com/creationix/http-parser-js/issues/57
PR-URL: https://github.com/nodejs/node/pull/24006
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'lib/internal/child_process.js')
-rw-r--r-- | lib/internal/child_process.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/internal/child_process.js b/lib/internal/child_process.js index ddb7e58d7c8..2f19f28b591 100644 --- a/lib/internal/child_process.js +++ b/lib/internal/child_process.js @@ -38,8 +38,6 @@ const { owner_symbol } = require('internal/async_hooks').symbols; const { convertToValidSignal } = require('internal/util'); const { isArrayBufferView } = require('internal/util/types'); const spawn_sync = internalBinding('spawn_sync'); -const { HTTPParser } = internalBinding('http_parser'); -const { freeParser } = require('_http_common'); const { kStateSymbol } = require('internal/dgram'); const { @@ -57,6 +55,10 @@ const { SocketListSend, SocketListReceive } = SocketList; // Lazy loaded for startup performance. let StringDecoder; +// Lazy loaded for startup performance and to allow monkey patching of +// internalBinding('http_parser').HTTPParser. +let freeParser; +let HTTPParser; const MAX_HANDLE_RETRANSMISSIONS = 3; @@ -121,6 +123,12 @@ const handleConversion = { handle.onread = nop; socket._handle = null; socket.setTimeout(0); + + if (freeParser === undefined) + freeParser = require('_http_common').freeParser; + if (HTTPParser === undefined) + HTTPParser = internalBinding('http_parser').HTTPParser; + // In case of an HTTP connection socket, release the associated // resources if (socket.parser && socket.parser instanceof HTTPParser) { |