Skip to content

Commit 43755c0

Browse files
committed
Auto merge of #1321 - dlevy47:bugfix/no-proxy, r=alexcrichton
Currently, cargo uses `curl_easy_setopt` to explicitly set the http proxy on a curl handle if any of the following are present: * cargo config `http.proxy` * git config `http.proxy` * `HTTP_PROXY` environment variable The act of explicitly setting the http proxy disables curl's logic for determining which proxy to use for a URL, and breaks the `no_proxy` environment variable. This PR privatizes `cargo::ops::registry::http_proxy` and adds an additional function `cargo::ops::registry::http_proxy_exists` to determine whether or not to use the `git2-curl` subtransport.
2 parents 9f60229 + 8eb28ad commit 43755c0

File tree

3 files changed

+27
-8
lines changed

3 files changed

+27
-8
lines changed

src/bin/cargo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ fn init_git_transports(config: &Config) {
255255
// Only use a custom transport if a proxy is configured, right now libgit2
256256
// doesn't support proxies and we have to use a custom transport in this
257257
// case. The custom transport, however, is not as well battle-tested.
258-
match cargo::ops::http_proxy(config) {
259-
Ok(Some(..)) => {}
258+
match cargo::ops::http_proxy_exists(config) {
259+
Ok(true) => {}
260260
_ => return
261261
}
262262

src/cargo/ops/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub use self::lockfile::{write_lockfile, write_pkg_lockfile};
1717
pub use self::cargo_test::{run_tests, run_benches, TestOptions};
1818
pub use self::cargo_package::package;
1919
pub use self::registry::{publish, registry_configuration, RegistryConfig};
20-
pub use self::registry::{registry_login, search, http_proxy, http_handle};
20+
pub use self::registry::{registry_login, search, http_proxy_exists, http_handle};
2121
pub use self::registry::{modify_owners, yank, OwnersOptions};
2222
pub use self::cargo_fetch::{fetch};
2323
pub use self::cargo_pkgid::pkgid;

src/cargo/ops/registry.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ pub fn http_handle(config: &Config) -> CargoResult<http::Handle> {
173173
Ok(handle)
174174
}
175175

176-
/// Find a globally configured HTTP proxy if one is available.
176+
/// Find an explicit HTTP proxy if one is available.
177177
///
178-
/// Favor cargo's `http.proxy`, then git's `http.proxy`, then finally a
179-
/// HTTP_PROXY env var.
180-
pub fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
178+
/// Favor cargo's `http.proxy`, then git's `http.proxy`. Proxies specified
179+
/// via environment variables are picked up by libcurl.
180+
fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
181181
match try!(config.get_string("http.proxy")) {
182182
Some((s, _)) => return Ok(Some(s)),
183183
None => {}
@@ -191,7 +191,26 @@ pub fn http_proxy(config: &Config) -> CargoResult<Option<String>> {
191191
}
192192
Err(..) => {}
193193
}
194-
Ok(env::var("HTTP_PROXY").ok())
194+
Ok(None)
195+
}
196+
197+
/// Determine if an http proxy exists.
198+
///
199+
/// Checks the following for existence, in order:
200+
///
201+
/// * cargo's `http.proxy`
202+
/// * git's `http.proxy`
203+
/// * http_proxy env var
204+
/// * HTTP_PROXY env var
205+
/// * https_proxy env var
206+
/// * HTTPS_PROXY env var
207+
pub fn http_proxy_exists(config: &Config) -> CargoResult<bool> {
208+
if try!(http_proxy(config)).is_some() {
209+
Ok(true)
210+
} else {
211+
Ok(["http_proxy", "HTTP_PROXY",
212+
"https_proxy", "HTTPS_PROXY"].iter().any(|v| env::var(v).is_ok()))
213+
}
195214
}
196215

197216
pub fn http_timeout(config: &Config) -> CargoResult<Option<i64>> {

0 commit comments

Comments
 (0)