|
@ -43,21 +43,24 @@ chargen.listen(9000, ready); |
|
|
|
|
|
|
|
|
// Proxy to the chargen server.
|
|
|
// Proxy to the chargen server.
|
|
|
var proxy = http.createServer(function(req, res) { |
|
|
var proxy = http.createServer(function(req, res) { |
|
|
var c = http.createClient(9000, 'localhost'); |
|
|
|
|
|
|
|
|
|
|
|
var len = parseInt(req.headers['x-len'], 10); |
|
|
var len = parseInt(req.headers['x-len'], 10); |
|
|
assert.ok(len > 0); |
|
|
assert.ok(len > 0); |
|
|
|
|
|
|
|
|
var sent = 0; |
|
|
var sent = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
c.addListener('error', function(e) { |
|
|
function onError(e) { |
|
|
console.log('proxy client error. sent ' + sent); |
|
|
console.log('proxy client error. sent ' + sent); |
|
|
throw e; |
|
|
throw e; |
|
|
}); |
|
|
} |
|
|
|
|
|
|
|
|
var proxy_req = c.request(req.method, req.url, req.headers); |
|
|
var proxy_req = http.request({ |
|
|
proxy_req.addListener('response', function(proxy_res) { |
|
|
host: 'localhost', |
|
|
|
|
|
port: 9000, |
|
|
|
|
|
method: req.method, |
|
|
|
|
|
path: req.url, |
|
|
|
|
|
headers: req.headers |
|
|
|
|
|
}, function(proxy_res) { |
|
|
res.writeHead(proxy_res.statusCode, proxy_res.headers); |
|
|
res.writeHead(proxy_res.statusCode, proxy_res.headers); |
|
|
|
|
|
|
|
|
var count = 0; |
|
|
var count = 0; |
|
@ -74,7 +77,7 @@ var proxy = http.createServer(function(req, res) { |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
proxy_req.on('error', onError); |
|
|
proxy_req.end(); |
|
|
proxy_req.end(); |
|
|
}); |
|
|
}); |
|
|
proxy.listen(9001, ready); |
|
|
proxy.listen(9001, ready); |
|
@ -89,9 +92,12 @@ function call_chargen(list) { |
|
|
|
|
|
|
|
|
var recved = 0; |
|
|
var recved = 0; |
|
|
|
|
|
|
|
|
var req = http.createClient(9001, 'localhost').request('/', {'x-len': len}); |
|
|
var req = http.request({ |
|
|
|
|
|
port: 9001, |
|
|
req.addListener('response', function(res) { |
|
|
host: 'localhost', |
|
|
|
|
|
path: '/', |
|
|
|
|
|
headers: {'x-len': len} |
|
|
|
|
|
}, function(res) { |
|
|
|
|
|
|
|
|
res.addListener('data', function(d) { |
|
|
res.addListener('data', function(d) { |
|
|
recved += d.length; |
|
|
recved += d.length; |
|
@ -115,7 +121,7 @@ function call_chargen(list) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
serversRunning = 0; |
|
|
var serversRunning = 0; |
|
|
function ready() { |
|
|
function ready() { |
|
|
if (++serversRunning < 2) return; |
|
|
if (++serversRunning < 2) return; |
|
|
call_chargen([100, 1000, 10000, 100000, 1000000]); |
|
|
call_chargen([100, 1000, 10000, 100000, 1000000]); |
|
|