9

When I tried to get data from REST service, i meet the HPE_HEADER_OVERFLOW error as follow:

error

var options = {
     host: "something.com",
     port: 80,
     path: "/somepath...",
     method: 'POST'
};

var request = http.request(options, function(res) {
	res.setEncoding('utf8');
	res.on('data', function(chunk) {
		// Do something
	});
	res.on('end', function() {
		// Do something 
	});
	request.on('error', function(e) {
		// Do something
	});
});

request.end();

The length of path parameter in the options is 413.

Does anyone meet this issue? Is this service-side issue or node-side issue?

Please give some idea about it, thanks a lot.

1
  • BTW, I tried to make ajax call in browser, it works well. Commented Feb 11, 2016 at 0:36

5 Answers 5

9

node app.js --max-http-header-size=80000

They made the header size configurable. Check the following links.

https://nodejs.org/api/cli.html#cli_max_http_header_size_size

https://github.com/nodejs/node/issues/24692

Sign up to request clarification or add additional context in comments.

1 Comment

I added the --max-http-header-size=80000 as a runtime argument in the launch.json in Visual Studio Code, and finally got it to work. I used runtimeArgs: [ ... ], not args: [...]
7

I think you'll find more stuff here and here

In a nutshell, Node.js has 80 KB limit for headers size which are big enough for most requests on the web (for example Apache has 8190 bytes limit). If that service somehow has so huge headers you can recompile node with -DHTTP_MAX_HEADER_SIZE=xxxx argument.

5 Comments

Hi man, thanks for your answer, it is very useful for me, but it didn't solve my issue. I just checked the the header size, it didn't exceed the limitation.
Maybe you've run out from system limits or something like this (selinux/apparmor/etc or Node was build with some non-standart options)? I'd like to reproduce this issue if you provide more information (uri and body at least).
Thanks man for the more suggestions, I just fixed this issue, that's because the REST service always use Content-Encoding: deflate, but when I made the API call, i didn't pass header Accept-Encoding: gzip, deflate. I don't know why the error happen, but the issue has been resolved.
Oh, seems non-properly server stuff. Happy to help somehow.
2

After digging a bit, the default parser node uses is the problem. The solution is to get a new parser:

npm install http-parser-js

then, just before you require http/https, change the parser. You have to end up having something similar to this:

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

If for some reason you want to use node's default parser, assuming your file is called 'app.js', you must use the header size flag like this:

node --max-http-header-size=81000 app.js

Comments

0

I have the same question, but my backend script is PHP. And I return the response header with some internal information including SQL and internal API url, thus the reponse headers is so big that exceeds the max-header-size and encountered this error. You can consider minishing the response header size in some case

Comments

0

Use Base64 encoding for the Header data which is causing HPE_HEADER_OVERFLOW like below:

headers: {Cookie: Buffer.from('_oauth2******************************2YJ9Y=').toString('base64')}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.