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.

Steve Gao
  • 585
  • 2
  • 5
  • 24

4 Answers4

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.

loadaverage
  • 1,028
  • 1
  • 11
  • 16
  • 1
    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. – Steve Gao Feb 11 '16 at 05:23
  • 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). – loadaverage Feb 11 '16 at 05:45
  • 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. – Steve Gao Feb 11 '16 at 06:22
  • Oh, seems non-properly server stuff. Happy to help somehow. – loadaverage Feb 11 '16 at 07:06
  • 1
    Actually only 8kb now :( https://github.com/Azure/azure-cosmos-js/issues/221#issuecomment-455584383 – DShook Sep 10 '19 at 20:17
7

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

rahulroy9202
  • 2,730
  • 3
  • 32
  • 45
  • 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: [...]` – Martin Lottering Jun 12 '19 at 12:07
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
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