diff --git a/lib/net.js b/lib/net.js index 6174b40eac..4b2622be0d 100644 --- a/lib/net.js +++ b/lib/net.js @@ -667,8 +667,7 @@ Socket.prototype.__defineGetter__('bytesWritten', function() { encoding = this._pendingEncoding; state.buffer.forEach(function(el) { - el = el[0]; - bytes += Buffer.byteLength(el[0], el[1]); + bytes += Buffer.byteLength(el.chunk); }); if (data) diff --git a/test/simple/test-http-byteswritten.js b/test/simple/test-http-byteswritten.js index b5e8e579a4..fc090b17dc 100644 --- a/test/simple/test-http-byteswritten.js +++ b/test/simple/test-http-byteswritten.js @@ -34,6 +34,15 @@ var httpServer = http.createServer(function(req, res) { console.log('ok'); }); res.writeHead(200, { 'Content-Type': 'text/plain' }); + + // Write 1mb to cause some requests to buffer + var chunk = new Array(1024).join('A'); + for (var i = 0; i < 1024; i++) { + res.write(chunk); + } + // Get .bytesWritten while buffer is not empty + assert(res.connection.bytesWritten > 0); + res.end(body); });