11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciif (!common.hasCrypto) 41cb0ef41Sopenharmony_ci common.skip('missing crypto'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 71cb0ef41Sopenharmony_ciconst https = require('https'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst options = { 101cb0ef41Sopenharmony_ci key: fixtures.readKey('agent1-key.pem'), 111cb0ef41Sopenharmony_ci cert: fixtures.readKey('agent1-cert.pem') 121cb0ef41Sopenharmony_ci}; 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ciconst connections = {}; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ciconst server = https.createServer(options, (req, res) => { 171cb0ef41Sopenharmony_ci const interval = setInterval(() => { 181cb0ef41Sopenharmony_ci res.write('data'); 191cb0ef41Sopenharmony_ci }, 1000); 201cb0ef41Sopenharmony_ci interval.unref(); 211cb0ef41Sopenharmony_ci}); 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ciserver.on('connection', (connection) => { 241cb0ef41Sopenharmony_ci const key = `${connection.remoteAddress}:${connection.remotePort}`; 251cb0ef41Sopenharmony_ci connection.on('close', () => { 261cb0ef41Sopenharmony_ci delete connections[key]; 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci connections[key] = connection; 291cb0ef41Sopenharmony_ci}); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_cifunction shutdown() { 321cb0ef41Sopenharmony_ci server.close(common.mustSucceed()); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci for (const key in connections) { 351cb0ef41Sopenharmony_ci connections[key].destroy(); 361cb0ef41Sopenharmony_ci delete connections[key]; 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci} 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ciserver.listen(0, () => { 411cb0ef41Sopenharmony_ci const requestOptions = { 421cb0ef41Sopenharmony_ci hostname: '127.0.0.1', 431cb0ef41Sopenharmony_ci port: server.address().port, 441cb0ef41Sopenharmony_ci path: '/', 451cb0ef41Sopenharmony_ci method: 'GET', 461cb0ef41Sopenharmony_ci rejectUnauthorized: false 471cb0ef41Sopenharmony_ci }; 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci const req = https.request(requestOptions, (res) => { 501cb0ef41Sopenharmony_ci res.on('data', () => {}); 511cb0ef41Sopenharmony_ci setImmediate(shutdown); 521cb0ef41Sopenharmony_ci }); 531cb0ef41Sopenharmony_ci req.end(); 541cb0ef41Sopenharmony_ci}); 55