2010-04-14 01:22:12 +02:00
|
|
|
require('../common');
|
|
|
|
var sys = require("sys"),
|
|
|
|
fs = require("fs"),
|
|
|
|
http = require("http"),
|
|
|
|
url = require("url");
|
|
|
|
|
|
|
|
// Produce a very large response.
|
|
|
|
var chargen = http.createServer(function (req, res) {
|
2010-04-14 01:43:15 +02:00
|
|
|
var chunk = '01234567890123456789';
|
|
|
|
var len = req.headers['x-len'];
|
|
|
|
res.writeHead(200, {"transfer-encoding":"chunked"});
|
|
|
|
for (var i=0; i<len; i++) {
|
|
|
|
print(',');
|
|
|
|
res.write(chunk);
|
|
|
|
}
|
|
|
|
res.end();
|
2010-04-14 01:22:12 +02:00
|
|
|
});
|
|
|
|
chargen.listen(9000);
|
|
|
|
|
|
|
|
// Proxy to the chargen server.
|
|
|
|
var proxy = http.createServer(function (req, res) {
|
2010-04-14 01:43:15 +02:00
|
|
|
var c = http.createClient(9000, 'localhost')
|
|
|
|
var proxy_req = c.request(req.method, req.url, req.headers);
|
|
|
|
proxy_req.addListener('response', function(proxy_res) {
|
|
|
|
res.writeHead(proxy_res.statusCode, proxy_res.headers);
|
|
|
|
proxy_res.addListener('data', function(chunk) {
|
|
|
|
print('.');
|
2010-04-14 01:22:12 +02:00
|
|
|
res.write(chunk);
|
2010-04-14 01:43:15 +02:00
|
|
|
});
|
|
|
|
proxy_res.addListener('end', function() {
|
2010-04-14 01:22:12 +02:00
|
|
|
res.end();
|
|
|
|
});
|
2010-04-14 01:43:15 +02:00
|
|
|
});
|
|
|
|
proxy_req.end();
|
2010-04-14 01:22:12 +02:00
|
|
|
});
|
|
|
|
proxy.listen(9001);
|
|
|
|
|
2010-04-14 01:43:15 +02:00
|
|
|
var done = false;
|
2010-04-14 01:22:12 +02:00
|
|
|
|
|
|
|
function call_chargen(list) {
|
|
|
|
if (list.length > 0) {
|
|
|
|
sys.debug("calling chargen for " + list[0] + " chunks.");
|
|
|
|
var req = http.createClient(9001, 'localhost').request('/', {'x-len': list[0]});
|
|
|
|
req.addListener('response', function(res) {
|
|
|
|
res.addListener('end', function() {
|
|
|
|
sys.debug("end for " + list[0] + " chunks.");
|
|
|
|
list.shift();
|
|
|
|
call_chargen(list);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
req.end();
|
2010-04-14 01:43:15 +02:00
|
|
|
} else {
|
2010-04-14 01:22:12 +02:00
|
|
|
sys.puts("End of list.");
|
|
|
|
proxy.end();
|
|
|
|
chargen.end();
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
call_chargen([ 100, 1000, 10000, 100000, 1000000 ]);
|
|
|
|
|
|
|
|
process.addListener('exit', function () {
|
|
|
|
assert.ok(done);
|
|
|
|
});
|