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.
51 lines
1.3 KiB
51 lines
1.3 KiB
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
var http = require('http');
|
||
15 years ago
|
|
||
14 years ago
|
var body = 'hello world\n';
|
||
15 years ago
|
|
||
14 years ago
|
var server = http.createServer(function(req, res) {
|
||
|
res.writeHead(200, {'Content-Length': body.length});
|
||
15 years ago
|
res.write(body);
|
||
|
res.end();
|
||
|
});
|
||
|
|
||
14 years ago
|
var connectCount = 0;
|
||
13 years ago
|
var agent = new http.Agent({maxSockets: 1});
|
||
|
var headers = {'connection': 'keep-alive'};
|
||
12 years ago
|
var name = agent.getName({ port: common.PORT });
|
||
15 years ago
|
|
||
14 years ago
|
server.listen(common.PORT, function() {
|
||
13 years ago
|
http.get({
|
||
|
path: '/', headers: headers, port: common.PORT, agent: agent
|
||
|
}, function(response) {
|
||
|
assert.equal(agent.sockets[name].length, 1);
|
||
|
assert.equal(agent.requests[name].length, 2);
|
||
12 years ago
|
response.resume();
|
||
14 years ago
|
});
|
||
13 years ago
|
|
||
13 years ago
|
http.get({
|
||
|
path: '/', headers: headers, port: common.PORT, agent: agent
|
||
|
}, function(response) {
|
||
|
assert.equal(agent.sockets[name].length, 1);
|
||
|
assert.equal(agent.requests[name].length, 1);
|
||
12 years ago
|
response.resume();
|
||
14 years ago
|
});
|
||
13 years ago
|
|
||
|
http.get({
|
||
|
path: '/', headers: headers, port: common.PORT, agent: agent
|
||
|
}, function(response) {
|
||
13 years ago
|
response.on('end', function() {
|
||
13 years ago
|
assert.equal(agent.sockets[name].length, 1);
|
||
|
assert(!agent.requests.hasOwnProperty(name));
|
||
14 years ago
|
server.close();
|
||
15 years ago
|
});
|
||
12 years ago
|
response.resume();
|
||
15 years ago
|
});
|
||
13 years ago
|
});
|
||
|
|
||
|
process.on('exit', function() {
|
||
|
assert(!agent.sockets.hasOwnProperty(name));
|
||
|
assert(!agent.requests.hasOwnProperty(name));
|
||
15 years ago
|
});
|