Skip to content

Commit e633b0f

Browse files
committed
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.
1 parent 1067054 commit e633b0f

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

Diff for: lib/http-proxy.js

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module.exports.createProxyServer = module.exports.createServer = function create
4242
* ws : <true/false, if you want to proxy websockets>
4343
* xfwd : <true/false, adds x-forward headers>
4444
* secure : <true/false, verify SSL certificate>
45+
* localAddress : <Local interface string to bind for outgoing connections>
4546
* }
4647
*
4748
* NOTE: `options.ws` and `options.ssl` are optional.

Diff for: lib/http-proxy/common.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
4545

4646
outgoing.agent = options.agent || false;
4747
outgoing.path = url.parse(req.url).path;
48+
outgoing.localAddress = options.localAddress;
4849
return outgoing;
4950
};
5051

Diff for: test/lib-http-proxy-common-test.js

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('lib/http-proxy/common.js', function () {
1515
port : 'you',
1616
},
1717
headers: {'fizz': 'bang', 'overwritten':true},
18+
localAddress: 'local.address',
1819
},
1920
{
2021
method : 'i',
@@ -34,6 +35,7 @@ describe('lib/http-proxy/common.js', function () {
3435
expect(outgoing.headers.pro).to.eql('xy');
3536
expect(outgoing.headers.fizz).to.eql('bang');
3637
expect(outgoing.headers.overwritten).to.eql(true);
38+
expect(outgoing.localAddress).to.eql('local.address');
3739
});
3840

3941
it('should set the agent to false if none is given', function () {

0 commit comments

Comments
 (0)