mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
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.
This commit is contained in:
parent
10670540ac
commit
e633b0f7e4
@ -42,6 +42,7 @@ module.exports.createProxyServer = module.exports.createServer = function create
|
|||||||
* ws : <true/false, if you want to proxy websockets>
|
* ws : <true/false, if you want to proxy websockets>
|
||||||
* xfwd : <true/false, adds x-forward headers>
|
* xfwd : <true/false, adds x-forward headers>
|
||||||
* secure : <true/false, verify SSL certificate>
|
* secure : <true/false, verify SSL certificate>
|
||||||
|
* localAddress : <Local interface string to bind for outgoing connections>
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* NOTE: `options.ws` and `options.ssl` are optional.
|
* NOTE: `options.ws` and `options.ssl` are optional.
|
||||||
|
|||||||
@ -45,6 +45,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
|
|||||||
|
|
||||||
outgoing.agent = options.agent || false;
|
outgoing.agent = options.agent || false;
|
||||||
outgoing.path = url.parse(req.url).path;
|
outgoing.path = url.parse(req.url).path;
|
||||||
|
outgoing.localAddress = options.localAddress;
|
||||||
return outgoing;
|
return outgoing;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@ describe('lib/http-proxy/common.js', function () {
|
|||||||
port : 'you',
|
port : 'you',
|
||||||
},
|
},
|
||||||
headers: {'fizz': 'bang', 'overwritten':true},
|
headers: {'fizz': 'bang', 'overwritten':true},
|
||||||
|
localAddress: 'local.address',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
method : 'i',
|
method : 'i',
|
||||||
@ -34,6 +35,7 @@ describe('lib/http-proxy/common.js', function () {
|
|||||||
expect(outgoing.headers.pro).to.eql('xy');
|
expect(outgoing.headers.pro).to.eql('xy');
|
||||||
expect(outgoing.headers.fizz).to.eql('bang');
|
expect(outgoing.headers.fizz).to.eql('bang');
|
||||||
expect(outgoing.headers.overwritten).to.eql(true);
|
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 () {
|
it('should set the agent to false if none is given', function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user