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

A first draft of proxy auto-detection #326

Closed
wants to merge 4 commits into from

Conversation

LouisStAmour
Copy link
Contributor

@LouisStAmour LouisStAmour commented Jun 24, 2017

  • Changed proxyEnabled boolean to a proxyConfiguration setting for clarity, but this could be converted back to a boolean if desired.
  • Turned the checkbox for manual proxy setting into radio options for automatic or manual.
  • Added a basic migration for state from the boolean to the 'auto' or 'manual' values of proxyConfiguration (haven't investigated how this works, just copied response...)
  • Changed network.js to wait for a promise from the proxy lookup
  • Referenced Google's code to understand common possible values for PAC responses and wrote fresh code to map them to CURL proxy URLs
  • If proxyConfiguration set to manual, existing logic still applies, untouched.
  • Log the results of the lookup in the timeline -- only if any proxies needed to be set.

Notes

  • I was surprised to discover that electron required in network.js refers to the Renderer but to keep the code portable, I reference both electron.session and electron.remote.getCurrentWebContents().session. It only now occurs to me that if I haven't tested the code block with electron.session, I should probably remove it, as I'm not sure if I need electron.session or electron.session.defaultSession or something else. (I'm relatively new to Electron...)
  • Non-curl calls automatically use the PAC, so it could be documented that the proxyConfiguration setting only affects Curl calls when set to manual. How to use a PAC could also be documented or linked to. (It was kind of magic to see the Charles Web Proxy auto-configuration get picked up by this code...)
  • I didn't write any tests, sorry! Not sure if it would help with test-writing or documentation, but here's Chrome's unit tests of their PAC response parser: https://github.com/adobe/chromium/blob/master/net/proxy/proxy_server_unittest.cc

Screenshots

screen shot 2017-06-24 at 1 08 33 am
screen shot 2017-06-24 at 1 08 45 am

Related Issue: #215

@LouisStAmour
Copy link
Contributor Author

Interesting. Seems I need to handle rejections on the promise to have the builds pass. And the tests run under a different context, given the error UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 8): TypeError: _electron2.default.remote.getCurrentWebContents is not a function

@LouisStAmour
Copy link
Contributor Author

Also, I know it hasn’t been your style up until now, but could you credit “Louis St-Amour” or visibly link to this pull request in the Changelog, if this goes in? I’m probably not alone in thinking that a little recognition can go a long way – and a subtle reminder in the change log that this is an open source piece of software might encourage more developer-customers to submit PRs like mine as a way of collectively giving back.

Copy link
Contributor

@gschier gschier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like where this is going! Left a few comments to point you in the right direction.

@@ -17,7 +17,7 @@ export function init () {
httpProxy: '',
httpsProxy: '',
noProxy: '',
proxyEnabled: false,
proxyConfiguration: 'auto',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should extract this to constants.js for reusability.

return settings;
}

if (settings.proxyEnabled === true) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably still have an extra state for off in order to respect the current behavior?

}
} else {
setOpt(Curl.option.PROXY, '');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line disabled Curl from automatically using HTTP_PROXY and HTTPS_PROXY and NO_PROXY environment variables. Maybe this could be part of the auto configuration, though?

}
if (noProxy) {
setOpt(Curl.option.NOPROXY, noProxy);
const proxyPromise = new Promise((resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably move this to a separate function (similar to network/authentication.js) now that it's so complex.

@@ -509,7 +541,7 @@ export function _actuallySend (renderedRequest, workspace, settings) {
respond({statusMessage, error});
});

curl.perform();
proxyPromise.then(() => curl.perform());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insomnia prefers async/await over promises, so this can be change to

await proxyPromise; 

// ...

curl.perform();

@gschier
Copy link
Contributor

gschier commented Jun 29, 2017

Also, I know it hasn’t been your style up until now, but could you credit “Louis St-Amour” or visibly link to this pull request in the Changelog, if this goes in? I’m probably not alone in thinking that a little recognition can go a long way – and a subtle reminder in the change log that this is an open source piece of software might encourage more developer-customers to submit PRs like mine as a way of collectively giving back.

I love the idea of linking the PR in the changelog @LouisStAmour. That would be a great way to show the involvement from the community.

@gschier
Copy link
Contributor

gschier commented Aug 3, 2017

Are you still working on this @LouisStAmour?

@LouisStAmour
Copy link
Contributor Author

Ah sorry, I meant to get back to it but was swamped with work. Might have a chance this Saturday though. :)

@gschier
Copy link
Contributor

gschier commented Aug 10, 2017

No problem @LouisStAmour. I'll leave this PR open for ya 😄

@gschier
Copy link
Contributor

gschier commented Nov 7, 2017

I'm going to close this PR for now since it's getting kind of stale but feel free to bring it back to life if you want. I think it would be a great feature 😄

@gschier gschier closed this Nov 7, 2017
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.

2 participants