Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Add support for reading http.proxy setting #639

Merged
merged 2 commits into from
Dec 30, 2016

Conversation

ibigbug
Copy link
Contributor

@ibigbug ibigbug commented Nov 22, 2016

Make go get honor http.proxy setting so that user can not only provide their proxy settings via environment variables

@msftclas
Copy link

Hi @ibigbug, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution!

This seems like a small (but important) contribution, so no Contribution License Agreement is required at this point. Real humans will now evaluate your PR.

TTYL, MSBOT;

@ibigbug
Copy link
Contributor Author

ibigbug commented Nov 22, 2016

Oh ci complains.

@@ -115,9 +115,11 @@ function installTools(goVersion: SemVersion, missing?: string[]) {

outputChannel.appendLine(''); // Blank line for spacing.

let http_proxy = vscode.workspace.getConfiguration('http').get('proxy');
let https_proxy = http_proxy; // default proxy for http & https
Copy link
Contributor

Choose a reason for hiding this comment

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

@ibigbug Sorry for the very late review.

Have you tested the case where http_proxy is not set in settings , but is set in the environment variable?
In that case will the value set in the environment variable make its way to the child process running the go get command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ramya-rao-a Yeah. I'm sure http_proxy in environment variables and open VS code from this environment using $ code can make go get work through proxy, though it's limited use case. User may often not open VS code through terminal and for OS X users (like me) and other Linux users, environment variables for terminal and GUI are always isolated, this is the main consideration for this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

@ibigbug I understand the use case you are trying to solve. My question was for the use case where a user might have set the env var for http_proxy, but not in settings. What happens then, with your code changes?

I tested your code in 2 scenarios in Windows, this is what I see for the env that gets passed to the child process running the go get

  1. When http_proxy is set in env var but not in VS Code settings
    image

  2. When different values are set for http_proxy in env var and VS Code settings
    image

You will have to do 2 changes I believe

  1. Use upper case while setting the http_proxy variable
  2. If there is no VS Code setting for http_proxy, then do not change the process.env

1. set both lower and upper case proxy environment variable
2. do not touch process.env when http.proxy setting is not present
let env = process.env;
if (httpProxy) {
env = Object.assign({}, process.env, {
http_proxy: httpProxy,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ramya-rao-a Thanks for pointing out the problems which I did't test carefully.

  1. I believe golang follows both lower and upper case proxy env vars: https://github.com/golang/go/blob/master/src/net/http/transport.go#L246 , do you think that it's OK to set both lower and upper case env vars here?
  2. I've added an detection if http.proxy was present.

Copy link
Contributor

Choose a reason for hiding this comment

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

any benefits of setting both upper and lower case?
Setting just the upper case should do so that if any that was set outside vs code get overridden.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I believe there are.

In case go get are calling some external tools such as wget to download third party resources or other tools like wget which read lowercase setting from environment variables: https://www.gnu.org/software/wget/manual/wget.html#Proxies

So I think setting both can be safer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good. Only thing pending is the failing tests in travis. Can you debug and see if it fails in your local set up as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found the failed test case is Test diffUtils.getEdits however I have no idea how does this commit make a difference on that. I'll have a local debug to see what happened.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ramya-rao-a It's interesting that running 'npm t` on current master branch also gets 6 failed tests. I wonder if there are any dependencies have had a breaking change?

Copy link
Contributor

Choose a reason for hiding this comment

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

I have fixed the tests in master. Re-running the travis tests for this PR keeps using the version of master before my fix.
So will go ahead and merge this without waiting for tests to turn green for this PR.

I was out on winter holidays, so couldn't help wrap this up sooner.
Thanks for your PR and I look forward to more in the future

@ramya-rao-a ramya-rao-a merged commit bcb1e2a into microsoft:master Dec 30, 2016
@ibigbug ibigbug deleted the feat/honor-proxy-setting branch December 30, 2016 02:27
mattetti added a commit to mattetti/vscode-go that referenced this pull request Jan 11, 2017
* 'master' of github.com:mattetti/vscode-go: (128 commits)
  Add telemetry support for the Go extension
  Add dlv path to error msg when dlv not found
  Fixes microsoft#465 outline offset problem in No-English language (microsoft#699)
  fix coverage display when editor changes to undefined (microsoft#693)
  Add support for reading http.proxy setting (microsoft#639)
  Fixing flaky unit tests
  Refactor for corner cases
  Reduce noise in console log due to errors from hover
  Changelog for next update 0.6.51
  Remove space after brackets in snippet as per microsoft#628
  Fixes microsoft#647 Strip version from autocompleted pkgs from gopkg.in (microsoft#659)
  Fixes microsoft#647 Support vendor pkgs from root of GOPATH/src (microsoft#660)
  Fixes microsoft#640 Use spawn to handle big data from gocode (microsoft#661)
  Fixed wrong workspace when one gopath is the substring of another. (microsoft#658)
  Fix "gotests" when generates test for current function for type methods (microsoft#657)
  Add benchmark function snippet (microsoft#648)
  Fix "Go to Definition" when running Go HEAD (microsoft#655)
  Fixes microsoft#642 Only add -d once to formatflags (microsoft#644)
  Updating Changelog and package.json for 0.6.50 update
  Log errors to console
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants