5

I have a simple node script to process some data from my home automation API. Everything worked fine till last Node update. Now, with Node version 4.3.0 or 5.6.0, the http module gives me this error:

{ [Error: Parse Error] bytesParsed: 193, code: 'HPE_UNEXPECTED_CONTENT_LENGTH' }

An example of the API call causing the error, it just returns one number (a temperature):

HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 5
Content-Type: application/json
Transfer-Encoding: chunked

21.81

And a code to reproduce an error:

const http = require("http");
const url = "http://127.0.0.1:8083/ZWaveAPI/Run/devices[11].instances[2].commandClasses[49].data[1].val.value";

http.get(url, (res) => {
    // consume response body
    res.resume();
}).on("error", (e) => {
    console.log(e);
});

I think that error related to the CVE-2016-2216 Response Splitting Vulnerability, but I tried to run the script with mentioned there --security-revert=CVE-2016-2216 flag and it didn't help. Any ideas?

2 Answers 2

6

I found this commit log. The problem seems is Content-Length and Transfer-encoding: chunked headers exist together:

the server is sending both a Content-Length header and a Transfer-Encoding: chunked header, which is a violation of the HTTP spec.

3
  • Well, this explains it. Thank you.
    – graycrow
    Feb 20, 2016 at 20:52
  • For the 4.x branch the commit is here: github.com/nodejs/node/commit/0eae95eae3 http-parser 2.5.1 .
    – S'pht'Kr
    Mar 1, 2016 at 19:04
  • 1
    Hello, @Vahagn . I am trying to do a post with https request, but I am also getting this bug. My request has no headers. Can you help me? Thanks. Apr 26, 2017 at 21:26
1

As said in the previous answer this is node design as per HTTP standards. i got this issue when I was trying to access REST-API (a content disposition call) in my DEV server from my Angular App running in my local machine. API was not adding these headers Content-Length and Transfer Encoding. The issue resolved when the app was also deployed to Dev server (Angular App and REST API in same server).

From what I understood, Remove one header if both are being added in API or Try deploying app in Server.

This is a useful link on this issue - https://github.com/request/request/issues/2091

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.