Closed
Description
- Version: v7.6.0
- Platform: Linux 4.4.0-59-generic Adding more specific README URLs to io.js, keeping node in too #80-Ubuntu x86_64 GNU/Linux
Subsystem: http - ClientRequest
I was making a request that had a string with a special character. In a buffer the character's size is 3 instead of the regular 1. The request would fail with a socket hang up and it took awhile to figure out why the request was failing. If there could be a more detailed error message for when there is a mismatch between the content-length and the actual payload that would be appreciated.
Simplest Example to Reproduce
const http = require( 'http' );
const requestData = '–';
http.request( {
headers: {
accept: 'application/json',
'content-type': 'application/json',
'content-length': requestData.length
},
host: 'localhost',
port: 3000,
path: '/foo',
method: 'post'
}, ( res )=>{
const accResponseBody = [];
res
.on( 'data', console.log )
.on( 'error', console.log );
} )
.on( 'error', console.log )
.end( requestData );
Expected Behavior
{ Error: Incorrect content-length }
Current Behavior
{ Error: socket hang up
at createHangUpError (_http_client.js:302:15)
at Socket.socketOnEnd (_http_client.js:394:23)
at emitNone (events.js:91:20)
at Socket.emit (events.js:186:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9) code: 'ECONNRESET' }