From 9f932e1183754ddddf2ea235ee86be892073864a Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Sun, 10 Dec 2017 19:31:55 -0500 Subject: [PATCH] Use the custom HTTP transport when any HTTP settings are present --- src/bin/cargo.rs | 9 +++++---- src/cargo/ops/mod.rs | 2 +- src/cargo/ops/registry.rs | 13 +++++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/bin/cargo.rs b/src/bin/cargo.rs index e92bcdbe5..53025a235 100644 --- a/src/bin/cargo.rs +++ b/src/bin/cargo.rs @@ -398,10 +398,11 @@ fn search_directories(config: &Config) -> Vec { } fn init_git_transports(config: &Config) { - // Only use a custom transport if a proxy is configured, right now libgit2 - // doesn't support proxies and we have to use a custom transport in this - // case. The custom transport, however, is not as well battle-tested. - match cargo::ops::http_proxy_exists(config) { + // Only use a custom transport if any HTTP options are specified, + // such as proxies or custom certificate authorities. The custom + // transport, however, is not as well battle-tested. + + match cargo::ops::needs_custom_http_transport(config) { Ok(true) => {} _ => return, } diff --git a/src/cargo/ops/mod.rs b/src/cargo/ops/mod.rs index fa155b3f6..7c4a33d4b 100644 --- a/src/cargo/ops/mod.rs +++ b/src/cargo/ops/mod.rs @@ -17,7 +17,7 @@ pub use self::lockfile::{load_pkg_lockfile, write_pkg_lockfile}; pub use self::cargo_test::{run_tests, run_benches, TestOptions}; pub use self::cargo_package::{package, PackageOpts}; pub use self::registry::{publish, registry_configuration, RegistryConfig}; -pub use self::registry::{registry_login, search, http_proxy_exists, http_handle}; +pub use self::registry::{registry_login, search, needs_custom_http_transport, http_handle}; pub use self::registry::{modify_owners, yank, OwnersOptions, PublishOpts}; pub use self::registry::configure_http_handle; pub use self::cargo_fetch::fetch; diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 122837b46..bf6ba8135 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -277,6 +277,15 @@ pub fn http_handle(config: &Config) -> CargoResult { Ok(handle) } +pub fn needs_custom_http_transport(config: &Config) -> CargoResult { + let proxy_exists = http_proxy_exists(config)?; + let timeout = http_timeout(config)?; + let cainfo = config.get_path("http.cainfo")?; + let check_revoke = config.get_bool("http.check-revoke")?; + + Ok(proxy_exists || timeout.is_some() || cainfo.is_some() || check_revoke.is_some()) +} + /// Configure a libcurl http handle with the defaults options for Cargo pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<()> { // The timeout option for libcurl by default times out the entire transfer, @@ -329,7 +338,7 @@ fn http_proxy(config: &Config) -> CargoResult> { /// * `HTTP_PROXY` env var /// * `https_proxy` env var /// * `HTTPS_PROXY` env var -pub fn http_proxy_exists(config: &Config) -> CargoResult { +fn http_proxy_exists(config: &Config) -> CargoResult { if http_proxy(config)?.is_some() { Ok(true) } else { @@ -338,7 +347,7 @@ pub fn http_proxy_exists(config: &Config) -> CargoResult { } } -pub fn http_timeout(config: &Config) -> CargoResult> { +fn http_timeout(config: &Config) -> CargoResult> { if let Some(s) = config.get_i64("http.timeout")? { return Ok(Some(s.val)) } -- 2.30.2