Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...