summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2015-12-11 20:11:17 -0500
committerFedor Indutny <fedor@indutny.com>2015-12-12 12:48:29 -0500
commitacef181fde5f725f54e8e951618ac3bb38eaaca5 (patch)
treeacc2ae32c2bf209dd18647caf1bd22fe17c6ec1f
parentf050cab3d850ad94dcf28746d1f942e706aa4e4f (diff)
downloadandroid-node-v8-acef181fde5f725f54e8e951618ac3bb38eaaca5.tar.gz
android-node-v8-acef181fde5f725f54e8e951618ac3bb38eaaca5.tar.bz2
android-node-v8-acef181fde5f725f54e8e951618ac3bb38eaaca5.zip
https: support disabling session caching
Zero value of `maxCachedSessions` should disable TLS session caching in `https.Agent` PR-URL: https://github.com/nodejs/node/pull/4252 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
-rw-r--r--lib/https.js4
-rw-r--r--test/parallel/test-https-agent-disable-session-reuse.js60
2 files changed, 64 insertions, 0 deletions
diff --git a/lib/https.js b/lib/https.js
index 90b6346bd9..6f97991f98 100644
--- a/lib/https.js
+++ b/lib/https.js
@@ -138,6 +138,10 @@ Agent.prototype._getSession = function _getSession(key) {
};
Agent.prototype._cacheSession = function _cacheSession(key, session) {
+ // Cache is disabled
+ if (this.maxCachedSessions === 0)
+ return;
+
// Fast case - update existing entry
if (this._sessionCache.map[key]) {
this._sessionCache.map[key] = session;
diff --git a/test/parallel/test-https-agent-disable-session-reuse.js b/test/parallel/test-https-agent-disable-session-reuse.js
new file mode 100644
index 0000000000..551f0150bf
--- /dev/null
+++ b/test/parallel/test-https-agent-disable-session-reuse.js
@@ -0,0 +1,60 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+
+if (!common.hasCrypto) {
+ console.log('1..0 # Skipped: missing crypto');
+ return;
+}
+
+const TOTAL_REQS = 2;
+
+const https = require('https');
+const crypto = require('crypto');
+
+const fs = require('fs');
+
+const options = {
+ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
+ cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
+};
+
+const clientSessions = [];
+var serverRequests = 0;
+
+const agent = new https.Agent({
+ maxCachedSessions: 0
+});
+
+const server = https.createServer(options, function(req, res) {
+ serverRequests++;
+ res.end('ok');
+}).listen(common.PORT, function() {
+ var waiting = TOTAL_REQS;
+ function request() {
+ const options = {
+ agent: agent,
+ port: common.PORT,
+ rejectUnauthorized: false
+ };
+
+ https.request(options, function(res) {
+ clientSessions.push(res.socket.getSession());
+
+ res.resume();
+ res.on('end', function() {
+ if (--waiting !== 0)
+ return request();
+ server.close();
+ });
+ }).end();
+ }
+ request();
+});
+
+process.on('exit', function() {
+ assert.equal(serverRequests, TOTAL_REQS);
+ assert.equal(clientSessions.length, TOTAL_REQS);
+ assert.notEqual(clientSessions[0].toString('hex'),
+ clientSessions[1].toString('hex'));
+});