From e633b0f7e4fd719d809eaeb4725e589f79c271ab Mon Sep 17 00:00:00 2001 From: Sam Beran Date: Tue, 11 Feb 2014 15:01:03 -0600 Subject: [PATCH] Add support for localAddress When we make outgoing requests, we may want to bind to a specific local address. This change allows the localAddress property to be specified via the options object. --- lib/http-proxy.js | 1 + lib/http-proxy/common.js | 1 + test/lib-http-proxy-common-test.js | 2 ++ 3 files changed, 4 insertions(+) diff --git a/lib/http-proxy.js b/lib/http-proxy.js index 34029e8..b7bc7a6 100644 --- a/lib/http-proxy.js +++ b/lib/http-proxy.js @@ -42,6 +42,7 @@ module.exports.createProxyServer = module.exports.createServer = function create * ws : * xfwd : * secure : + * localAddress : * } * * NOTE: `options.ws` and `options.ssl` are optional. diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index 7897578..1b981e2 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -45,6 +45,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) { outgoing.agent = options.agent || false; outgoing.path = url.parse(req.url).path; + outgoing.localAddress = options.localAddress; return outgoing; }; diff --git a/test/lib-http-proxy-common-test.js b/test/lib-http-proxy-common-test.js index 7398a0e..8cb9391 100644 --- a/test/lib-http-proxy-common-test.js +++ b/test/lib-http-proxy-common-test.js @@ -15,6 +15,7 @@ describe('lib/http-proxy/common.js', function () { port : 'you', }, headers: {'fizz': 'bang', 'overwritten':true}, + localAddress: 'local.address', }, { method : 'i', @@ -34,6 +35,7 @@ describe('lib/http-proxy/common.js', function () { expect(outgoing.headers.pro).to.eql('xy'); expect(outgoing.headers.fizz).to.eql('bang'); expect(outgoing.headers.overwritten).to.eql(true); + expect(outgoing.localAddress).to.eql('local.address'); }); it('should set the agent to false if none is given', function () {