Nodejs request: HPE_INVALID_HEADER_TOKEN

2019-05-11 07:11发布

问题:

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?

回答1:

The solution is this library: https://www.npmjs.com/package/http-parser-js

So to fix your problem:

  1. npm install http-parser-js

  2. Add this code before require('request')

    process.binding('http_parser').HTTPParser = require('http-parser-js').HTTPParser;