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

pick up http_proxy and https_proxy environment variables #1347

Open
2 of 5 tasks
toymil opened this issue Nov 21, 2023 · 8 comments
Open
2 of 5 tasks

pick up http_proxy and https_proxy environment variables #1347

toymil opened this issue Nov 21, 2023 · 8 comments

Comments

@toymil
Copy link

toymil commented Nov 21, 2023

💡 Feature description

Pick up http_proxy and https_proxy environment variables for all the download tasks (like downloading chromedriver when executing wasm-pack test --chrome --headless for the first time).

This will prevent frustrating network problems like #605 and #1345 , since there is currently no way to set proxy for wasm-pack.

Solution

From what I can tell from the source code, wasm-pack both directly and indirectly uses ureq for all the download tasks, indirectly through binary-install.

  • impl a feature flag to enable auto proxy pick up by default in ureq
    • wait for version release
  • update binary-install's ureq dep, and enable (or pass through since binary-install is a lib) related feature flag
    • wait for version release
  • update wasm-pack's binary-install and ureq dep, enable related feature flag
@algesten
Copy link

I believe this is done. It's released in ureq 2.8.0 (and we're on 2.9.0 now).

@toymil toymil changed the title pick up http_proxy and https_proxy environment variables update ureq dependency to at least v2.8.0, to pick up http_proxy and https_proxy environment variables Nov 21, 2023
@toymil
Copy link
Author

toymil commented Nov 21, 2023

I did the following:

  • clone ureq, checkout 2.9.0
    • modified to debug print proxy settings each time a request is made, to confirm if proxy envvars have been picked up or not.
  • clone binary-install, checkout v0.2.0
    • change Cargo.toml to use local modified ureq
  • clone wasm-pack, checkout v0.12.1
    • change Cargo.toml to use local modified binary-install and ureq
  • install this local version of wasm-pack for tests

and the tests are negative, none of the network requests picked up proxy envvars...

Will do a bit more digging to see if I missed anything.

@toymil
Copy link
Author

toymil commented Nov 21, 2023

I see that wasm-pack and binary-install all calls ureq::get(..) to download, which initializes an agent with the default setting AgentBuilder::new().build(), and by default try_proxy_from_env of AgentBuilder is set to false, so it ended up not using the proxy environment variables.

https://github.com/algesten/ureq/blob/260213b3e2a55e40f7132374034520455d497789/src/agent.rs#L252-L275

https://github.com/algesten/ureq/blob/260213b3e2a55e40f7132374034520455d497789/src/agent.rs#L323-L332

@algesten
Copy link

Yes. To use this, create an Agent, enable the environment option, and make the request from the agent.

@toymil
Copy link
Author

toymil commented Nov 21, 2023

Change try_proxy_from_env default to true made everything work. Here is what I modified:

  • clone ureq, checkout 2.9.0
    • modified to debug print proxy settings each time a request is made, to confirm if proxy env vars have been picked up or not.
    • modified AgentBuilder::new() to enable try_proxy_from_env by default
  • clone binary-install, checkout v0.2.0
    • change Cargo.toml to use local modified ureq
  • clone wasm-pack, checkout v0.12.1
    • change Cargo.toml to use local modified binary-install and ureq
  • install this local version of wasm-pack for tests

And wasm-pack successfully picked up my proxy env vars.


The most simple scenario would be for ureq to default try_proxy_from_env to true, then the changes needed here are:

  • wasm-pack and binary-install both update the ureq dependency.
  • optionally enable socks-proxy feature flag for ureq, so socks proxies in http(s)_proxy env var are also supported.

If not, then we need to manually construct Agent and call AgentBuilder::try_proxy_from_env(mut self, do_try: bool) to enable the behavior each time we need to download. Since there is multiple places in the code where ureq are called, this would be tricky.

@toymil
Copy link
Author

toymil commented Nov 21, 2023

@algesten may I ask why try_proxy_from_env is default to false? The comment wrote:

The default is false, i.e. not detecting proxy from env since this is a potential security risk.

But most of the tooling I use does do this by default. So why not enable it by default and provide an option for library users to disable instead?

@toymil
Copy link
Author

toymil commented Nov 21, 2023

But most of the tooling I use does do this by default. So why not enable it by default and provide an option for library users to disable instead?

I understand that it might always been the case for network libs to disable this behavior by default, and the reason why "most of the tooling I use does do this by default" is because the tooling devs manually enabled it.

Is this the case?

@algesten
Copy link

The motivation is hidden in the PR. I should probably bring it out in the docs. https://github.com/algesten/ureq/pull/649/files#r1290992185

@toymil toymil changed the title update ureq dependency to at least v2.8.0, to pick up http_proxy and https_proxy environment variables pick up http_proxy and https_proxy environment variables Nov 22, 2023
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

No branches or pull requests

2 participants