net, http, https: add localAddress option

Binds to a local address before making the outgoing connection.
This commit is contained in:
Dmitry Nizovtsev authored and Ben Noordhuis committed 2012-03-06 13:35:49 +01:00
1 parent 9ea5a4c468
commit 1e9bcf26ce
8 files changed
+186 -20

No files matched your search

+21 -3
View File
@@ -51,12 +51,30 @@ exports.createServer = function(opts, requestListener) {
// HTTPS agents.
function createConnection(port, host, options) {
options.port = port;
options.host = host;
function createConnection(/* [port, host, options] */) {
var options = {};
if (typeof arguments[0] === 'object') {
options = arguments[0];
} else if (typeof arguments[1] === 'object') {
options = arguments[1];
options.port = arguments[0];
} else if (typeof arguments[2] === 'object') {
options = arguments[2];
options.port = arguments[0];
options.host = arguments[1];
} else {
if (typeof arguments[0] === 'number') {
options.port = arguments[0];
}
if (typeof arguments[1] === 'string') {
options.host = arguments[1];
}
}
return tls.connect(options);
}
function Agent(options) {
http.Agent.call(this, options);
this.createConnection = createConnection;