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.
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!
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.
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": "https://example.com/getFile", "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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With