diff options
author | Shigeki Ohtsu <ohtsu@iij.ad.jp> | 2012-08-30 19:11:05 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-08-31 02:23:36 +0400 |
commit | f347077e786b1ca78d44e2c77b1bc1366735af76 (patch) | |
tree | 007c4b78feb55d4bdd768a0aec1e6e50afb05c69 /lib | |
parent | 9603f08f21987d5367d98267a16179a61e4400c1 (diff) |
tls: support unix domain socket/named pipe in tls.connect
Diffstat (limited to 'lib')
-rw-r--r-- | lib/net.js | 1 | ||||
-rw-r--r-- | lib/tls.js | 45 |
2 files changed, 19 insertions, 27 deletions
diff --git a/lib/net.js b/lib/net.js index d0a4c641bf4..efed0cacde8 100644 --- a/lib/net.js +++ b/lib/net.js @@ -106,6 +106,7 @@ function normalizeConnectArgs(args) { var cb = args[args.length - 1]; return (typeof cb === 'function') ? [options, cb] : [options]; } +exports._normalizeConnectArgs = normalizeConnectArgs; /* called when creating new Socket, or when re-using a closed Socket */ diff --git a/lib/tls.js b/lib/tls.js index 350b5776d08..ee3695567cc 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -1183,34 +1183,24 @@ Server.prototype.SNICallback = function(servername) { // }); // // -exports.connect = function(/* [port, host], options, cb */) { - var options, port, host, cb; - - if (typeof arguments[0] === 'object') { - options = arguments[0]; - } else if (typeof arguments[1] === 'object') { - options = arguments[1]; - port = arguments[0]; - } else if (typeof arguments[2] === 'object') { - options = arguments[2]; - port = arguments[0]; - host = arguments[1]; - } else { - // This is what happens when user passes no `options` argument, we can't - // throw `TypeError` here because it would be incompatible with old API - if (typeof arguments[0] === 'number') { - port = arguments[0]; - } - if (typeof arguments[1] === 'string') { - host = arguments[1]; - } +function normalizeConnectArgs(listArgs) { + var args = net._normalizeConnectArgs(listArgs); + var options = args[0]; + var cb = args[1]; + + if (typeof listArgs[1] === 'object') { + options = util._extend(options, listArgs[1]); + } else if (typeof listArgs[2] === 'object') { + options = util._extend(options, listArgs[2]); } - options = util._extend({ port: port, host: host }, options || {}); + return (cb) ? [options, cb] : [options]; +} - if (typeof arguments[arguments.length - 1] === 'function') { - cb = arguments[arguments.length - 1]; - } +exports.connect = function(/* [port, host], options, cb */) { + var args = normalizeConnectArgs(arguments); + var options = args[0]; + var cb = args[1]; var socket = options.socket ? options.socket : new net.Stream(); @@ -1235,11 +1225,12 @@ exports.connect = function(/* [port, host], options, cb */) { } if (!options.socket) { - socket.connect({ + var connect_opt = (options.path && !options.port) ? {path: options.path} : { port: options.port, host: options.host, localAddress: options.localAddress - }); + }; + socket.connect(connect_opt); } pair.on('secure', function() { |