Skip to content

Commit

Permalink
Add support for localAddress
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sberan committed Feb 11, 2014
1 parent 1067054 commit e633b0f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module.exports.createProxyServer = module.exports.createServer = function create
* ws : <true/false, if you want to proxy websockets>
* xfwd : <true/false, adds x-forward headers>
* secure : <true/false, verify SSL certificate>
* localAddress : <Local interface string to bind for outgoing connections>
* }
*
* NOTE: `options.ws` and `options.ssl` are optional.
Expand Down
1 change: 1 addition & 0 deletions lib/http-proxy/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
2 changes: 2 additions & 0 deletions test/lib-http-proxy-common-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('lib/http-proxy/common.js', function () {
port : 'you',
},
headers: {'fizz': 'bang', 'overwritten':true},
localAddress: 'local.address',
},
{
method : 'i',
Expand All @@ -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 () {
Expand Down

0 comments on commit e633b0f

Please sign in to comment.