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

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

node.js - Nodejs request: HPE_INVALID_HEADER_TOKEN

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...