forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https: add extra options to Agent#getName()
Adds the remaining options from tls.createSecureContext() to the string generated by Agent#getName(). This allows https.request() to accept the options and generate unique sockets appropriately. PR-URL: nodejs#16402 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
Showing
5 changed files
with
127 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const crypto = require('crypto'); | ||
const https = require('https'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const options = { | ||
key: fixtures.readKey('agent1-key.pem'), | ||
cert: fixtures.readKey('agent1-cert.pem'), | ||
ca: fixtures.readKey('ca1-cert.pem') | ||
}; | ||
|
||
const server = https.Server(options, function(req, res) { | ||
res.writeHead(200); | ||
res.end('hello world\n'); | ||
}); | ||
|
||
function getBaseOptions(port) { | ||
return { | ||
path: '/', | ||
port: port, | ||
ca: options.ca, | ||
rejectUnautorized: true, | ||
servername: 'agent1', | ||
}; | ||
} | ||
|
||
const updatedValues = new Map([ | ||
['dhparam', fixtures.readKey('dh2048.pem')], | ||
['ecdhCurve', 'secp384r1'], | ||
['honorCipherOrder', true], | ||
['secureOptions', crypto.constants.SSL_OP_CIPHER_SERVER_PREFERENCE], | ||
['secureProtocol', 'TLSv1_method'], | ||
['sessionIdContext', 'sessionIdContext'], | ||
]); | ||
|
||
function variations(iter, port, cb) { | ||
const { done, value } = iter.next(); | ||
if (done) { | ||
return common.mustCall(cb); | ||
} else { | ||
const [key, val] = value; | ||
return common.mustCall(function(res) { | ||
res.resume(); | ||
https.globalAgent.once('free', common.mustCall(function() { | ||
https.get( | ||
Object.assign({}, getBaseOptions(port), { [key]: val }), | ||
variations(iter, port, cb) | ||
); | ||
})); | ||
}); | ||
} | ||
} | ||
|
||
server.listen(0, common.mustCall(function() { | ||
const port = this.address().port; | ||
const globalAgent = https.globalAgent; | ||
globalAgent.keepAlive = true; | ||
https.get(getBaseOptions(port), variations( | ||
updatedValues.entries(), | ||
port, | ||
common.mustCall(function(res) { | ||
res.resume(); | ||
globalAgent.once('free', common.mustCall(function() { | ||
// Verify that different keep-alived connections are created | ||
// for the base call and each variation | ||
const keys = Object.keys(globalAgent.freeSockets); | ||
assert.strictEqual(keys.length, 1 + updatedValues.size); | ||
let i = 1; | ||
for (const [, value] of updatedValues) { | ||
assert.ok( | ||
keys[i].startsWith(value.toString() + ':') || | ||
keys[i].endsWith(':' + value.toString()) || | ||
keys[i].includes(':' + value.toString() + ':') | ||
); | ||
i++; | ||
} | ||
globalAgent.destroy(); | ||
server.close(); | ||
})); | ||
}) | ||
)); | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.