Auto merge of #4781 - alexcrichton:beta-next, r=alexcrichton

[beta] Reconfigure curl handles after reset

This is a backport of https://github.com/rust-lang/cargo/pull/4780
This commit is contained in:
bors 2017-12-05 17:05:29 +00:00
commit 45043115c9
5 changed files with 25 additions and 9 deletions

View File

@ -19,6 +19,7 @@ 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::{modify_owners, yank, OwnersOptions, PublishOpts};
pub use self::registry::configure_http_handle;
pub use self::cargo_fetch::fetch;
pub use self::cargo_pkgid::pkgid;
pub use self::resolve::{resolve_ws, resolve_ws_precisely, resolve_with_previous};

View File

@ -273,6 +273,16 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
// connect phase as well as a "low speed" timeout so if we don't receive
// many bytes in a large-ish period of time then we time out.
let mut handle = Easy::new();
configure_http_handle(config, &mut handle)?;
Ok(handle)
}
/// 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,
// but we probably don't want this. Instead we only set timeouts for the
// connect phase as well as a "low speed" timeout so if we don't receive
// many bytes in a large-ish period of time then we time out.
handle.connect_timeout(Duration::new(30, 0))?;
handle.low_speed_limit(10 /* bytes per second */)?;
handle.low_speed_time(Duration::new(30, 0))?;
@ -290,7 +300,7 @@ pub fn http_handle(config: &Config) -> CargoResult<Easy> {
handle.connect_timeout(Duration::new(timeout as u64, 0))?;
handle.low_speed_time(Duration::new(timeout as u64, 0))?;
}
Ok(handle)
Ok(())
}
/// Find an explicit HTTP proxy if one is available.

View File

@ -10,7 +10,6 @@ use hex::ToHex;
use serde_json;
use core::{PackageId, SourceId};
use ops;
use sources::git;
use sources::registry::{RegistryData, RegistryConfig, INDEX_LOCK};
use util::network;
@ -159,7 +158,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
//
// This way if there's a problem the error gets printed before we even
// hit the index, which may not actually read this configuration.
ops::http_handle(self.config)?;
self.config.http()?;
self.repo()?;
self.head.set(None);

View File

@ -633,7 +633,11 @@ impl Config {
let http = self.easy.get_or_try_init(|| {
ops::http_handle(self).map(RefCell::new)
})?;
http.borrow_mut().reset();
{
let mut http = http.borrow_mut();
http.reset();
ops::configure_http_handle(self, &mut http)?;
}
Ok(http)
}
}

View File

@ -79,9 +79,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
#[test]
fn frozen_flag_preserves_old_lockfile() {
Package::new("foo", "0.1.0").publish();
let cksum = Package::new("foo", "0.1.0").publish();
let old_lockfile =
let old_lockfile = format!(
r#"[root]
name = "zzz"
version = "0.0.1"
@ -95,8 +95,10 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f9e0a16bdf5c05435698fa27192d89e331b22a26a972c34984f560662544453b"
"#;
"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "{}"
"#,
cksum,
);
let p = project("bar")
.file("Cargo.toml", r#"
@ -109,7 +111,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
foo = "0.1.0"
"#)
.file("src/lib.rs", "")
.file("Cargo.lock", old_lockfile)
.file("Cargo.lock", &old_lockfile)
.build();
assert_that(p.cargo("build").arg("--locked"),