-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #12242 - weihanglo:rust-1.71.0, r=ehuss
[beta-1.70] backport #12234 Beta backports: - #12234 In order to make CI pass, the following PRs are also cherry-picked: - #12241
- Loading branch information
Showing
6 changed files
with
134 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
use std::task::Poll; | ||
|
||
pub mod proxy; | ||
pub mod retry; | ||
pub mod sleep; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Utilities for network proxies. | ||
use crate::util::config::CargoHttpConfig; | ||
use crate::util::config::Config; | ||
|
||
/// Proxy environment variables that are picked up by libcurl. | ||
const LIBCURL_HTTP_PROXY_ENVS: [&str; 4] = | ||
["http_proxy", "HTTP_PROXY", "https_proxy", "HTTPS_PROXY"]; | ||
|
||
/// Finds an explicit HTTP proxy if one is available. | ||
/// | ||
/// Favor [Cargo's `http.proxy`], then [Git's `http.proxy`]. | ||
/// Proxies specified via environment variables are picked up by libcurl. | ||
/// See [`LIBCURL_HTTP_PROXY_ENVS`]. | ||
/// | ||
/// [Cargo's `http.proxy`]: https://doc.rust-lang.org/nightly/cargo/reference/config.html#httpproxy | ||
/// [Git's `http.proxy`]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-httpproxy | ||
pub fn http_proxy(http: &CargoHttpConfig) -> Option<String> { | ||
if let Some(s) = &http.proxy { | ||
return Some(s.into()); | ||
} | ||
git2::Config::open_default() | ||
.and_then(|cfg| cfg.get_string("http.proxy")) | ||
.ok() | ||
} | ||
|
||
/// Determine if an http proxy exists. | ||
/// | ||
/// Checks the following for existence, in order: | ||
/// | ||
/// * Cargo's `http.proxy` | ||
/// * Git's `http.proxy` | ||
/// * `http_proxy` env var | ||
/// * `HTTP_PROXY` env var | ||
/// * `https_proxy` env var | ||
/// * `HTTPS_PROXY` env var | ||
pub fn http_proxy_exists(http: &CargoHttpConfig, config: &Config) -> bool { | ||
http_proxy(http).is_some() | ||
|| LIBCURL_HTTP_PROXY_ENVS | ||
.iter() | ||
.any(|v| config.get_env(v).is_ok()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters