Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

https: support 0 maxCachedSessions #4252

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
59 changes: 59 additions & 0 deletions test/parallel/test-https-agent-disable-session-reuse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a check for clientSessions.length here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack.

assert.notEqual(clientSessions[0].toString('hex'),
clientSessions[1].toString('hex'));
});