mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
12 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
var fs = require('fs');
|
||
|
var http = require('http');
|
||
|
|
||
|
var body = 'hello world\n';
|
||
|
|
||
12 years ago
|
var sawFinish = false;
|
||
|
process.on('exit', function() {
|
||
|
assert(sawFinish);
|
||
|
console.log('ok');
|
||
|
});
|
||
|
|
||
12 years ago
|
var httpServer = http.createServer(function(req, res) {
|
||
12 years ago
|
httpServer.close();
|
||
|
|
||
12 years ago
|
res.on('finish', function() {
|
||
12 years ago
|
sawFinish = true;
|
||
12 years ago
|
assert(typeof(req.connection.bytesWritten) === 'number');
|
||
|
assert(req.connection.bytesWritten > 0);
|
||
|
});
|
||
|
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
||
12 years ago
|
|
||
12 years ago
|
// Write 1.5mb to cause some requests to buffer
|
||
|
// Also, mix up the encodings a bit.
|
||
|
var chunk = new Array(1024 + 1).join('7');
|
||
12 years ago
|
var bchunk = new Buffer(chunk);
|
||
12 years ago
|
for (var i = 0; i < 1024; i++) {
|
||
|
res.write(chunk);
|
||
12 years ago
|
res.write(bchunk);
|
||
12 years ago
|
res.write(chunk, 'hex');
|
||
12 years ago
|
}
|
||
|
// Get .bytesWritten while buffer is not empty
|
||
|
assert(res.connection.bytesWritten > 0);
|
||
|
|
||
12 years ago
|
res.end(body);
|
||
|
});
|
||
|
|
||
|
httpServer.listen(common.PORT, function() {
|
||
12 years ago
|
http.get({ port: common.PORT });
|
||
12 years ago
|
});
|
||
|
|