diff options
author | Fedor Indutny <fedor.indutny@gmail.com> | 2011-05-20 02:42:13 +0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2011-05-19 14:45:42 -0700 |
commit | 21724ecaec63aad529a1ce2f0eebd82e52d399e3 (patch) | |
tree | 307113d7315a20721fd63856d6ea6ee6ad879775 /lib/crypto.js | |
parent | 6461af1baa4ed1f9b1f521a9e7dda33b3b946eb5 (diff) | |
download | node-new-21724ecaec63aad529a1ce2f0eebd82e52d399e3.tar.gz |
Share SSL context between server connections
Fixes #1073.
Diffstat (limited to 'lib/crypto.js')
-rw-r--r-- | lib/crypto.js | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/crypto.js b/lib/crypto.js index c95103f3df..2a9225ae16 100644 --- a/lib/crypto.js +++ b/lib/crypto.js @@ -36,7 +36,7 @@ try { } -function Credentials(secureProtocol) { +function Credentials(secureProtocol, context) { if (!(this instanceof Credentials)) { return new Credentials(secureProtocol); } @@ -45,22 +45,28 @@ function Credentials(secureProtocol) { throw new Error('node.js not compiled with openssl crypto support.'); } - this.context = new SecureContext(); - - if (secureProtocol) { - this.context.init(secureProtocol); + if (context) { + this.context = context; + this.reuseContext = true; } else { - this.context.init(); - } + this.context = new SecureContext(); + if (secureProtocol) { + this.context.init(secureProtocol); + } else { + this.context.init(); + } + } } exports.Credentials = Credentials; -exports.createCredentials = function(options) { +exports.createCredentials = function(options, context) { if (!options) options = {}; - var c = new Credentials(options.secureProtocol); + var c = new Credentials(options.secureProtocol, context); + + if (context) return c; if (options.key) c.context.setKey(options.key); |