1'use strict'; 2const common = require('../common'); 3const fixtures = require('../common/fixtures'); 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const https = require('https'); 9 10const options = { 11 key: fixtures.readKey('agent1-key.pem'), 12 cert: fixtures.readKey('agent1-cert.pem') 13}; 14 15const TOTAL = 4; 16let waiting = TOTAL; 17 18const server = https.Server(options, function(req, res) { 19 if (--waiting === 0) server.close(); 20 21 const servername = req.socket.servername; 22 23 if (servername !== false) { 24 res.setHeader('x-sni', servername); 25 } 26 27 res.end('hello world'); 28}); 29 30server.listen(0, function() { 31 function expectResponse(id) { 32 return common.mustCall(function(res) { 33 res.resume(); 34 assert.strictEqual(res.headers['x-sni'], 35 id === false ? undefined : `sni.${id}`); 36 }); 37 } 38 39 const agent = new https.Agent({ 40 maxSockets: 1 41 }); 42 for (let j = 0; j < TOTAL; j++) { 43 https.get({ 44 agent: agent, 45 46 path: '/', 47 port: this.address().port, 48 host: '127.0.0.1', 49 servername: `sni.${j}`, 50 rejectUnauthorized: false 51 }, expectResponse(j)); 52 } 53 https.get({ 54 agent: agent, 55 56 path: '/', 57 port: this.address().port, 58 host: '127.0.0.1', 59 servername: '', 60 rejectUnauthorized: false 61 }, expectResponse(false)); 62}); 63