0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-28 22:46:31 +01:00
nodejs/test/parallel/test-http-keep-alive-close-on-header.js
isaacs 3e1b1dd4a9 Remove excessive copyright/license boilerplate
The copyright and license notice is already in the LICENSE file.  There
is no justifiable reason to also require that it be included in every
file, since the individual files are not individually distributed except
as part of the entire package.
2015-01-12 15:30:28 -08:00

78 lines
1.7 KiB
JavaScript

var common = require('../common');
var assert = require('assert');
var http = require('http');
var util = require('util');
var body = 'hello world\n';
var headers = {'connection': 'keep-alive'};
var server = http.createServer(function(req, res) {
res.writeHead(200, {'Content-Length': body.length, 'Connection': 'close'});
res.write(body);
res.end();
});
var connectCount = 0;
server.listen(common.PORT, function() {
var agent = new http.Agent({ maxSockets: 1 });
var name = agent.getName({ port: common.PORT });
var request = http.request({
method: 'GET',
path: '/',
headers: headers,
port: common.PORT,
agent: agent
}, function(res) {
assert.equal(1, agent.sockets[name].length);
res.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
connectCount++;
});
});
request.end();
request = http.request({
method: 'GET',
path: '/',
headers: headers,
port: common.PORT,
agent: agent
}, function(res) {
assert.equal(1, agent.sockets[name].length);
res.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
connectCount++;
});
});
request.end();
request = http.request({
method: 'GET',
path: '/',
headers: headers,
port: common.PORT,
agent: agent
}, function(response) {
response.on('end', function() {
assert.equal(1, agent.sockets[name].length);
server.close();
});
response.resume();
});
request.on('socket', function(s) {
s.on('connect', function() {
connectCount++;
});
});
request.end();
});
process.on('exit', function() {
assert.equal(3, connectCount);
});