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
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

57 lines
1.2 KiB
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
const https = require('https');
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/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(function() {}));
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', function(d) {});
setImmediate(shutdown);
});
req.end();
});