node/test/parallel/test-http-byteswritten.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

35 lines
954 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const body = 'hello world\n';
const httpServer = http.createServer(common.mustCall(function(req, res) {
httpServer.close();
res.on('finish', common.mustCall(function() {
assert.strictEqual(typeof req.connection.bytesWritten, 'number');
assert(req.connection.bytesWritten > 0);
}));
res.writeHead(200, { 'Content-Type': 'text/plain' });
// Write 1.5mb to cause some requests to buffer
// Also, mix up the encodings a bit.
const chunk = new Array(1024 + 1).join('7');
const bchunk = Buffer.from(chunk);
for (let i = 0; i < 1024; i++) {
res.write(chunk);
res.write(bchunk);
res.write(chunk, 'hex');
}
// Get .bytesWritten while buffer is not empty
assert(res.connection.bytesWritten > 0);
res.end(body);
}));
httpServer.listen(0, function() {
http.get({ port: this.address().port });
});