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
prodroy1 e2140697aa test: replace callback with arrow functions
PR-URL: https://github.com/nodejs/node/pull/24434
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-11-23 22:27:19 -08: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, (req, res) => {
const interval = setInterval(() => {
res.write('data');
}, 1000);
interval.unref();
});
server.on('connection', (connection) => {
const key = `${connection.remoteAddress}:${connection.remotePort}`;
connection.on('close', () => {
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, () => {
const requestOptions = {
hostname: '127.0.0.1',
port: server.address().port,
path: '/',
method: 'GET',
rejectUnauthorized: false
};
const req = https.request(requestOptions, (res) => {
res.on('data', () => {});
setImmediate(shutdown);
});
req.end();
});