Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit acef181

Browse filesBrowse files
committed
https: support disabling session caching
Zero value of `maxCachedSessions` should disable TLS session caching in `https.Agent` PR-URL: #4252 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent f050cab commit acef181
Copy full SHA for acef181

File tree

Expand file treeCollapse file tree

2 files changed

+64
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+64
-0
lines changed
Open diff view settings
Collapse file

‎lib/https.js‎

Copy file name to clipboardExpand all lines: lib/https.js
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ Agent.prototype._getSession = function _getSession(key) {
138138
};
139139

140140
Agent.prototype._cacheSession = function _cacheSession(key, session) {
141+
// Cache is disabled
142+
if (this.maxCachedSessions === 0)
143+
return;
144+
141145
// Fast case - update existing entry
142146
if (this._sessionCache.map[key]) {
143147
this._sessionCache.map[key] = session;
Collapse file
+60Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
10+
const TOTAL_REQS = 2;
11+
12+
const https = require('https');
13+
const crypto = require('crypto');
14+
15+
const fs = require('fs');
16+
17+
const options = {
18+
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
19+
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
20+
};
21+
22+
const clientSessions = [];
23+
var serverRequests = 0;
24+
25+
const agent = new https.Agent({
26+
maxCachedSessions: 0
27+
});
28+
29+
const server = https.createServer(options, function(req, res) {
30+
serverRequests++;
31+
res.end('ok');
32+
}).listen(common.PORT, function() {
33+
var waiting = TOTAL_REQS;
34+
function request() {
35+
const options = {
36+
agent: agent,
37+
port: common.PORT,
38+
rejectUnauthorized: false
39+
};
40+
41+
https.request(options, function(res) {
42+
clientSessions.push(res.socket.getSession());
43+
44+
res.resume();
45+
res.on('end', function() {
46+
if (--waiting !== 0)
47+
return request();
48+
server.close();
49+
});
50+
}).end();
51+
}
52+
request();
53+
});
54+
55+
process.on('exit', function() {
56+
assert.equal(serverRequests, TOTAL_REQS);
57+
assert.equal(clientSessions.length, TOTAL_REQS);
58+
assert.notEqual(clientSessions[0].toString('hex'),
59+
clientSessions[1].toString('hex'));
60+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.