I receive HPE_INVALID_HEADER_TOKEN
on a certain page using request
module. From what I've found on Google, this is caused by an incorrect / malformed server response, however the latter is not under my control. Can I configure request to ignore invalid headers or just give me the whole raw response for processing?
Node v12 has a new parser that is more strict with header validation, which can cause the same errors, especially with sites using Imperva/Incapsula that include an invalid header in HTTP 1.1 responses.
A temporary solution is to use the --http-parser=legacy
option in node's command line, or in the NODE_OPTIONS
environment variable.
Since v12.15.0
and v10.19.0
you can do this:
http.request(url, { insecureHTTPParser: true })
Additional information can be found here: https://github.com/nodejs/node/issues/27711#issuecomment-584621376
Edit: --http-parser=legacy
is no longer supported in recent versions (including minor versions of v12). A solution for newer node versions is to use --insecure-http-parser
instead.
The solution is this library: https://www.npmjs.com/package/http-parser-js
So to fix your problem:
npm install http-parser-js
Add this code before require('request')
process.binding('http_parser').HTTPParser = require('http-parser-js').HTTPParser;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With