-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
include a function to enable/disable proxy #13
base: master
Are you sure you want to change the base?
Conversation
maa105
commented
Jul 10, 2018
``` var globalTunnel = require('global-tunnel-ng'); globalTunnel.initialize({ host: '10.0.0.10', port: 8080, proxyAuth: 'userId:password', // optional authentication sockets: 50 // optional pool size for each http and https }, function(options) { return options.host.indexOf('google') >=0; // enable proxy for only google requests }); ```
``` var globalTunnel = require('global-tunnel-ng'); globalTunnel.initialize({ host: '10.0.0.10', port: 8080, proxyAuth: 'userId:password', // optional authentication sockets: 50 // optional pool size for each http and https }, function(options) { return options.host.indexOf('google') >=0; // enable proxy for only google requests }); ```
updated readme
Thanks for the PR! Could you include tests for this new feature? Also I think it would be better to pass the filter in the configuration object instead of using a new parameter. |
hello yes sure ill work on the test cases, but regarding the function I put it as an argument because of you clone the config object and I wasn't sure how that will affect the function |
It is true that the object is cloned with |
hello I added the test cases and made the proxyEnableFunction part of the config |
Cool feature 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check the comments, I don't think the feature will work as intended right now.
Im so sorry about how long it took to check your PR which led to a lot of changes needed to be merged from the master branch.
Thanks for contributing!
agent.proxy = proxyOpts; | ||
|
||
var orig = pick(agent, 'createConnection', 'addRequest'); | ||
|
||
// Make the tcp or tls connection go to the proxy, ignoring the | ||
// destination host:port arguments. | ||
agent.createConnection = function(port, host, options) { | ||
return orig.createConnection.call(this, this.proxy.port, this.proxy.host, options); | ||
var doProxy = !globalTunnel.proxyConfig.proxyEnableFunction || globalTunnel.proxyConfig.proxyEnableFunction(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proxyEnableFunction is called with no arguments.
whichAgent.request, | ||
sinon.match.has('path', expectConnect) | ||
); | ||
if(testParams.proxyEnableFunction !== false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests check for the existence of the option, not for its return value depending on the parameters it received
}); | ||
|
||
it('(got proxying set up)', function() { | ||
assert.isTrue(globalTunnel.isProxying); | ||
}); | ||
|
||
describe('with the request library', function() { | ||
it('will proxy http requests', function(done) { | ||
it('will' + (testParams.proxyEnableFunction === false ? ' not' : '') + ' proxy http requests', function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests check for the existence of the option, not for its return value depending on the parameters it received
Whats the status on this? I really could use a way of defining urls/hostnames/etc to disable proxy usage temporarely. Just like other tools use the NO_PROXY env variable. |
Hello, |