What Does This Error Mean: Hpe_Invalid_Constant?

I was receiving HPE_INVALID_CONSTANT when making HTTP requests with NodeJS the other day. They mysteriously stopped occurring recently, but I'm still baffled and curious what exactly HPE_INVALID_CONSTANT is trying to tell me.

My google search results are a bit slanted towards NodeJS, so I'm not picking up anything that describes more generally what this means. It looks like a system level error since it's all caps.

4 Answers

Think this answer is lated, but it can help some people.

I also had this problem and realized NodeJS doesn't support HTTP 0.9, that server's response contains no headers. In fact, in NodeJS documentation shows support to 1.0 and 1.1 http requests.

You can read a little more here in this issue.

1

The HPE_INVALID_CONSTANT means Http Parse Error and the invalid constant means that the response is malformed. So the parser can't parse it!

I encountered this issue because I was trying to compress files that were too small. In my specific case, I was creating a readstream of a file that was 83 bytes, and then piping it into a gzip, before finally piping it into the response

fs.createReadStream(file_path).pipe(gzip.createGzip()).pipe(res);

On the requester side, I was then trying to unzip the file

stream = request({"url": "", "timeout": 200000});

//This is where the error was getting thrown
stream.pipe(gzip.createGunzip())

It seems that trying to compress and then decompress a file with a size somewhere less than 200 bytes will totally break this, so that was a gotcha I encountered. I guess the moral of my story is don't compress files that are super tiny!

I've had the same issue when used not decoded params in request URL.

Example:

  1. Request to with whitespaces will cause an error

      Error: Parse Error
      at TLSSocket.socketOnData (_http_client.js:440:20)
      at emitOne (events.js:116:13)
      at TLSSocket.emit (events.js:211:7)
      at addChunk (_stream_readable.js:263:12)
      at readableAddChunk (_stream_readable.js:250:11)
      at TLSSocket.Readable.push (_stream_readable.js:208:10)
      at TLSWrap.onread (net.js:597:20)
    bytesParsed: 0,
    code: 'HPE_INVALID_CONSTANT',
    
  2. Request to will work fine

Your Answer

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

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest