Skip to content

Commit

Permalink
Auto merge of #5957 - lostiniceland:5717-curl-low_speed, r=alexcrichton
Browse files Browse the repository at this point in the history
Provide http-config option for curl low-speed-limit/time

Fixes #5717

Provides new override options for curl in Cargo http config-section.

```
[http]
timeout = 2
low-speed-limit = 5
```

Test with the following during crate-download
`sudo tc qdisc add dev eth0 handle 1: root htb default 11 && sudo tc class add dev eth0 parent 1: classid 1:1 htb rate 8bps && sudo tc class add dev eth0 parent 1:1 classid 1:11 htb rate 8bps`

Clear with
`sudo tc qdisc del dev eth0 root`
  • Loading branch information
bors committed Sep 3, 2018
2 parents dd196e0 + d6cde29 commit 86c9c51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
// 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))?;
handle.low_speed_limit(http_low_speed_limit(config)?)?;
if let Some(proxy) = http_proxy(config)? {
handle.proxy(&proxy)?;
}
Expand All @@ -390,6 +389,14 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
Ok(())
}

/// Find an override from config for curl low-speed-limit option, otherwise use default value
fn http_low_speed_limit(config: &Config) -> CargoResult<u32> {
if let Some(s) = config.get::<Option<u32>>("http.low-speed-limit")? {
return Ok(s);
}
Ok(10)
}

/// Find an explicit HTTP proxy if one is available.
///
/// Favor cargo's `http.proxy`, then git's `http.proxy`. Proxies specified
Expand Down
1 change: 1 addition & 0 deletions src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ proxy = "host:port" # HTTP proxy to use for HTTP requests (defaults to none)
timeout = 60000 # Timeout for each HTTP request, in milliseconds
cainfo = "cert.pem" # Path to Certificate Authority (CA) bundle (optional)
check-revoke = true # Indicates whether SSL certs are checked for revocation
low-speed-limit = 0 # Lower threshold for bytes/sec (10 = default, 0 = disabled)

[build]
jobs = 1 # number of parallel jobs, defaults to # of CPUs
Expand Down

0 comments on commit 86c9c51

Please sign in to comment.