mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
tls: support unix domain socket/named pipe in tls.connect
This commit is contained in:
parent
9603f08f21
commit
f347077e78
@ -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 */
|
||||
|
49
lib/tls.js
49
lib/tls.js
@ -1183,34 +1183,24 @@ Server.prototype.SNICallback = function(servername) {
|
||||
// });
|
||||
//
|
||||
//
|
||||
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]);
|
||||
}
|
||||
|
||||
return (cb) ? [options, cb] : [options];
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
options = util._extend({ port: port, host: host }, options || {});
|
||||
|
||||
if (typeof arguments[arguments.length - 1] === 'function') {
|
||||
cb = arguments[arguments.length - 1];
|
||||
}
|
||||
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() {
|
||||
|
49
test/simple/test-tls-connect-pipe.js
Normal file
49
test/simple/test-tls-connect-pipe.js
Normal file
@ -0,0 +1,49 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
var common = require('../common');
|
||||
var assert = require('assert');
|
||||
var tls = require('tls');
|
||||
var fs = require('fs');
|
||||
|
||||
var clientConnected = 0;
|
||||
var serverConnected = 0;
|
||||
|
||||
var options = {
|
||||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
||||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
||||
};
|
||||
|
||||
var server = tls.Server(options, function(socket) {
|
||||
++serverConnected;
|
||||
server.close();
|
||||
});
|
||||
server.listen(common.PIPE, function() {
|
||||
var client = tls.connect(common.PIPE, function() {
|
||||
++clientConnected;
|
||||
client.end();
|
||||
});
|
||||
});
|
||||
|
||||
process.on('exit', function() {
|
||||
assert.equal(clientConnected, 1);
|
||||
assert.equal(serverConnected, 1);
|
||||
});
|
Loading…
Reference in New Issue
Block a user