request / request-promise

The simplified HTTP request client 'request' with Promise support. Powered by Bluebird.
ISC License
4.76k stars 297 forks source link

Ignoring HPE_INVALID_HEADER_TOKEN error #319

Open WhiteyDude opened 5 years ago

WhiteyDude commented 5 years ago

When calling a certain site (https://tickets.wbstudiotour.co.uk/webstore/shop/ViewItems.aspx?CG=HPTST2&C=TIX2), I get thrown a HPE_INVALID_HEADER_TOKEN error. Further investigation shows this site is sending back a Server header with no colon or value.

Some digging lead me to find https://github.com/creationix/http-parser-js, which appears to resolve this issue by monkey patching in a different HTTPParser to the relevant binding:

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

However this monkey patch doesn't seem to change anything for me in request-promise. I'm unsure if request-promise maybe doesn't use this parser, or has its own custom parser?

jcbaey commented 5 years ago

Node v12 has a new parser that is more strict with header validation, which can cause the HPE_INVALID_HEADER_TOKEN errors.

A temporary solution is to use the --http-parser=legacy option in node's command line, or in the NODE_OPTIONS environment variable.

Either

node --http-parser=legacy index.js

or

export NODE_OPTIONS=--http-parser=legacy
node index.js