mirror of
https://github.com/nodejs/node.git
synced 2025-04-29 06:19:07 +00:00

There is no way to disable SNI extension when sending a request to HTTPS server. Setting `options.servername` to a falsy value would make Node.js core override it with either hostname or ip address. This change introduces a way to disable SNI completely if this is required for user's application. Setting `options.servername` to `` in `https.request` would disable overrides and thus disable the extension. PR-URL: https://github.com/nodejs/node/pull/27316 Reviewed-By: Steven R Loomis <srloomis@us.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
63 lines
1.3 KiB
JavaScript
63 lines
1.3 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const https = require('https');
|
|
|
|
const options = {
|
|
key: fixtures.readKey('agent1-key.pem'),
|
|
cert: fixtures.readKey('agent1-cert.pem')
|
|
};
|
|
|
|
const TOTAL = 4;
|
|
let waiting = TOTAL;
|
|
|
|
const server = https.Server(options, function(req, res) {
|
|
if (--waiting === 0) server.close();
|
|
|
|
const servername = req.socket.servername;
|
|
|
|
if (servername !== false) {
|
|
res.setHeader('x-sni', servername);
|
|
}
|
|
|
|
res.end('hello world');
|
|
});
|
|
|
|
server.listen(0, function() {
|
|
function expectResponse(id) {
|
|
return common.mustCall(function(res) {
|
|
res.resume();
|
|
assert.strictEqual(res.headers['x-sni'],
|
|
id === false ? undefined : `sni.${id}`);
|
|
});
|
|
}
|
|
|
|
const agent = new https.Agent({
|
|
maxSockets: 1
|
|
});
|
|
for (let j = 0; j < TOTAL; j++) {
|
|
https.get({
|
|
agent: agent,
|
|
|
|
path: '/',
|
|
port: this.address().port,
|
|
host: '127.0.0.1',
|
|
servername: `sni.${j}`,
|
|
rejectUnauthorized: false
|
|
}, expectResponse(j));
|
|
}
|
|
https.get({
|
|
agent: agent,
|
|
|
|
path: '/',
|
|
port: this.address().port,
|
|
host: '127.0.0.1',
|
|
servername: '',
|
|
rejectUnauthorized: false
|
|
}, expectResponse(false));
|
|
});
|