GeezerVison is showing github.com — https: use `servername` in agent key · nodejs/node@3213e5f
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/https.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -130,6 +130,10 @@ Agent.prototype.getName = function(options) { |
130 | 130 | if (options.rejectUnauthorized !== undefined) |
131 | 131 | name += options.rejectUnauthorized; |
132 | 132 |
|
| 133 | + name += ':'; |
| 134 | + if (options.servername && options.servername !== options.host) |
| 135 | + name += options.servername; |
| 136 | + |
133 | 137 | return name; |
134 | 138 | }; |
135 | 139 |
|
|
Collapse file
Copy file name to clipboard +52Lines changed: 52 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('assert'); |
| 4 | + |
| 5 | +if (!common.hasCrypto) { |
| 6 | + console.log('1..0 # Skipped: missing crypto'); |
| 7 | + return; |
| 8 | +} |
| 9 | +const https = require('https'); |
| 10 | + |
| 11 | +const fs = require('fs'); |
| 12 | + |
| 13 | +const options = { |
| 14 | + key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), |
| 15 | + cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') |
| 16 | +}; |
| 17 | + |
| 18 | +const TOTAL = 4; |
| 19 | +var waiting = TOTAL; |
| 20 | + |
| 21 | +const server = https.Server(options, function(req, res) { |
| 22 | + if (--waiting === 0) server.close(); |
| 23 | + |
| 24 | + res.writeHead(200, { |
| 25 | + 'x-sni': req.socket.servername |
| 26 | + }); |
| 27 | + res.end('hello world'); |
| 28 | +}); |
| 29 | + |
| 30 | +server.listen(common.PORT, function() { |
| 31 | + function expectResponse(id) { |
| 32 | + return common.mustCall(function(res) { |
| 33 | + res.resume(); |
| 34 | + assert.equal(res.headers['x-sni'], 'sni.' + id); |
| 35 | + }); |
| 36 | + } |
| 37 | + |
| 38 | + var agent = new https.Agent({ |
| 39 | + maxSockets: 1 |
| 40 | + }); |
| 41 | + for (var j = 0; j < TOTAL; j++) { |
| 42 | + https.get({ |
| 43 | + agent: agent, |
| 44 | + |
| 45 | + path: '/', |
| 46 | + port: common.PORT, |
| 47 | + host: '127.0.0.1', |
| 48 | + servername: 'sni.' + j, |
| 49 | + rejectUnauthorized: false |
| 50 | + }, expectResponse(j)); |
| 51 | + } |
| 52 | +}); |