|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const fs = require('fs'); |
| 4 | + |
| 5 | +if (!common.hasCrypto) { |
| 6 | + console.log('1..0 # Skipped: missing crypto'); |
| 7 | + return; |
| 8 | +} |
| 9 | +const https = require('https'); |
| 10 | + |
| 11 | +const options = { |
| 12 | + key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), |
| 13 | + cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') |
| 14 | +}; |
| 15 | + |
| 16 | +var connections = {}; |
| 17 | + |
| 18 | +var server = https.createServer(options, function(req, res) { |
| 19 | + var interval = setInterval(function() { |
| 20 | + res.write('data'); |
| 21 | + }, 1000); |
| 22 | + interval.unref(); |
| 23 | +}); |
| 24 | + |
| 25 | +server.on('connection', function(connection) { |
| 26 | + var key = connection.remoteAddress + ':' + connection.remotePort; |
| 27 | + connection.on('close', function() { |
| 28 | + delete connections[key]; |
| 29 | + }); |
| 30 | + connections[key] = connection; |
| 31 | +}); |
| 32 | + |
| 33 | +function shutdown() { |
| 34 | + server.close(common.mustCall(function() {})); |
| 35 | + |
| 36 | + for (var key in connections) { |
| 37 | + connections[key].destroy(); |
| 38 | + delete connections[key]; |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +server.listen(common.PORT, function() { |
| 43 | + var requestOptions = { |
| 44 | + hostname: '127.0.0.1', |
| 45 | + port: common.PORT, |
| 46 | + path: '/', |
| 47 | + method: 'GET', |
| 48 | + rejectUnauthorized: false |
| 49 | + }; |
| 50 | + |
| 51 | + var req = https.request(requestOptions, function(res) { |
| 52 | + res.on('data', function(d) {}); |
| 53 | + setImmediate(shutdown); |
| 54 | + }); |
| 55 | + req.end(); |
| 56 | +}); |
0 commit comments