0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-https-close.js
Alberto Lopez de Lara a9a0146c8b test: use common/fixtures in test-https-close
PR-URL: https://github.com/nodejs/node/pull/15870
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2017-10-12 18:23:41 -07:00

55 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fixtures = require('../common/fixtures');
const https = require('https');
const options = {
key: fixtures.readKey('agent1-key.pem'),
cert: fixtures.readKey('agent1-cert.pem')
};
const connections = {};
const server = https.createServer(options, function(req, res) {
const interval = setInterval(function() {
res.write('data');
}, 1000);
interval.unref();
});
server.on('connection', function(connection) {
const key = `${connection.remoteAddress}:${connection.remotePort}`;
connection.on('close', function() {
delete connections[key];
});
connections[key] = connection;
});
function shutdown() {
server.close(common.mustCall());
for (const key in connections) {
connections[key].destroy();
delete connections[key];
}
}
server.listen(0, function() {
const requestOptions = {
hostname: '127.0.0.1',
port: this.address().port,
path: '/',
method: 'GET',
rejectUnauthorized: false
};
const req = https.request(requestOptions, function(res) {
res.on('data', () => {});
setImmediate(shutdown);
});
req.end();
});