Getting HPE_UNEXPECTED_CONTENT_LENGTH error when trying to consume ElasticSearch from NodeJS

Issue #47 resolved
Former user created an issue

I'm trying to access ElasticSearch 5.3 with NodeJS 7.10 (using the axios library) and I'm getting this error: HPE_UNEXPECTED_CONTENT_LENGTH

Comments (5)

  1. Waldemar Hummer Account Deactivated

    Hi, thanks for reporting. Would you be able to provide a minimal test case / working example to reproduce the issue? Thanks.

  2. Demetrius Nunes

    Sure, using the standard http node library, I get this:

    req = http.request('http://localhost:4571/_nodes'); req.on('error', console.error); req.end();
    
    { Error: Parse Error
        at Socket.socketOnData (_http_client.js:411:20)
        at emitOne (events.js:96:13)
        at Socket.emit (events.js:191:7)
        at readableAddChunk (_stream_readable.js:178:18)
        at Socket.Readable.push (_stream_readable.js:136:10)
        at TCP.onread (net.js:561:20) bytesParsed: 35, code: 'HPE_UNEXPECTED_CONTENT_LENGTH' }
    

    I figured out the problem using curl:

    curl -i http://localhost:4571/_nodes       
    HTTP/1.0 200 OK
    Server: BaseHTTP/0.3 Python/2.7.13
    Date: Wed, 05 Jul 2017 14:30:00 GMT
    content-type: application/json; charset=UTF-8
    content-length: 5368
    Content-Length: 5368
    

    The Content-Length header is included twice in the response and that's what's messing up the NodeJS HTTP parser.

  3. Log in to comment