Skip to content
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

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

maa105
Copy link

@maa105 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
});

maa105 added 3 commits July 10, 2018 11:25
```
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
@MarcoScabbiolo
Copy link
Contributor

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.

@maa105
Copy link
Author

maa105 commented Jul 10, 2018

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

@MarcoScabbiolo
Copy link
Contributor

It is true that the object is cloned with lodash.clone and that would exclude the function, but the function can be added after cloning. I think it is better to include the function in the options to avoid having too many arguments.

@maa105 maa105 closed this Jul 12, 2018
@maa105 maa105 deleted the patch-1 branch July 12, 2018 05:23
@maa105 maa105 restored the patch-1 branch July 12, 2018 05:24
@maa105 maa105 reopened this Jul 12, 2018
@maa105
Copy link
Author

maa105 commented Jul 12, 2018

hello I added the test cases and made the proxyEnableFunction part of the config

@roccomuso
Copy link

Cool feature 👍

Copy link
Contributor

@MarcoScabbiolo MarcoScabbiolo left a 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();
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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

@pr4xx
Copy link

pr4xx commented Mar 29, 2019

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.

@ghost
Copy link

ghost commented Jul 4, 2019

Hello,
Are there any predictions when this option can be introduced?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants