Is monkey-patching still working?
disfated opened this issue · 3 comments
disfated commented
On node v12.13 having a hard time to make use of http-parser-js
.
This trick
process.binding('http_parser').HTTPParser = require('http-parser-js').HTTPParser;
seems not working any more.
Is anyone having success with it on actual node versions or I'm missing something?
Jimbly commented
I did some digging, and there's a bunch of things going wrong...
- Node's parser binding in v12 is now called 'http_parser_llhttp', however they did not add that to the whitelist of modules exposed through process.binding, so there's no way to override it. v13 renames it back to http_parser, so that's good, at least.
- Luckily, you can tell node v12 to use the older parser binding with
node --http-parser=legacy
, then it's called 'http_parser' again, which is monkey-patchable - Unfortunately, they changed the parser API again, in a way that
http-parser-js
does not handle (looks pretty minor, just changed it to empty constructor plus an .initialize() call instead of passing things in the constructor), so even with --http-parser=legacy, this module is not working- PRs welcome to fix this! I think that'll also fix it on node v13+, but v12 will probably require
--http-parser=legacy
in order to monkey patch.
- PRs welcome to fix this! I think that'll also fix it on node v13+, but v12 will probably require
Jimbly commented
I've fixed http-parser-js
to work on Node v12.x and v13.0.1. However, on Node v12, you must launch Node with node --http-parser=legacy
in order to monkey-patch. Should work after doing that, though, all tests are passing! Published to NPM as v0.5.2.
Jimbly commented
Monkey-patching is working as of all current Node versions (has been for quite a while, just closing this issue now). For reference, checked yesterday on
- v6.9.1
- v8.11.3
- v10.16.0
- v12.20.0 (requires
--http-parser=legacy
command line option) - v13.11.0
- v14.9.0
- v15.5.0