Skip to content

Commit 241fac0

Browse files
committed
Auto merge of #6271 - alexcrichton:h2, r=ehuss
Enable HTTP/2 by default This commit switches Cargo to using HTTP/2 by default. This is controlled via the `http.multiplexing` configuration variable and has been messaged out for testing [1] (although got very few responses). There's been surprisingly little fallout from parallel downloads, so let's see how this goes! [1]: https://internals.rust-lang.org/t/testing-cargos-parallel-downloads/8466
2 parents 5f448d5 + c181f49 commit 241fac0

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ bytesize = "1.0"
2222
crates-io = { path = "src/crates-io", version = "0.21" }
2323
crossbeam-utils = "0.5"
2424
crypto-hash = "0.3.1"
25-
curl = { version = "0.4.17", features = ['http2'] }
26-
curl-sys = "0.4.12"
25+
curl = { version = "0.4.19", features = ['http2'] }
26+
curl-sys = "0.4.15"
2727
env_logger = "0.5.11"
2828
failure = "0.1.2"
2929
filetime = "0.2"

src/cargo/core/package.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ use std::path::{Path, PathBuf};
77
use std::time::{Instant, Duration};
88

99
use bytesize::ByteSize;
10-
use curl;
11-
use curl_sys;
1210
use curl::easy::{Easy, HttpVersion};
1311
use curl::multi::{Multi, EasyHandle};
12+
use curl;
13+
use curl_sys;
14+
use failure::ResultExt;
1415
use lazycell::LazyCell;
1516
use semver::Version;
1617
use serde::ser;
@@ -327,7 +328,7 @@ impl<'cfg> PackageSet<'cfg> {
327328
// proxies.
328329
let mut multi = Multi::new();
329330
let multiplexing = config.get::<Option<bool>>("http.multiplexing")?
330-
.unwrap_or(false);
331+
.unwrap_or(true);
331332
multi.pipelining(false, multiplexing)
332333
.chain_err(|| "failed to enable multiplexing/pipelining in curl")?;
333334

@@ -451,12 +452,30 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
451452
handle.follow_location(true)?; // follow redirects
452453

453454
// Enable HTTP/2 to be used as it'll allow true multiplexing which makes
454-
// downloads much faster. Currently Cargo requests the `http2` feature
455-
// of the `curl` crate which means it should always be built in, so
456-
// treat it as a fatal error of http/2 support isn't found.
455+
// downloads much faster.
456+
//
457+
// Currently Cargo requests the `http2` feature of the `curl` crate
458+
// which means it should always be built in. On OSX, however, we ship
459+
// cargo still linked against the system libcurl. Building curl with
460+
// ALPN support for HTTP/2 requires newer versions of OSX (the
461+
// SecureTransport API) than we want to ship Cargo for. By linking Cargo
462+
// against the system libcurl then older curl installations won't use
463+
// HTTP/2 but newer ones will. All that to basically say we ignore
464+
// errors here on OSX, but consider this a fatal error to not activate
465+
// HTTP/2 on all other platforms.
457466
if self.set.multiplexing {
458-
handle.http_version(HttpVersion::V2)
459-
.chain_err(|| "failed to enable HTTP2, is curl not built right?")?;
467+
let result = handle.http_version(HttpVersion::V2);
468+
if cfg!(target_os = "macos") {
469+
if let Err(e) = result {
470+
warn!("ignoring HTTP/2 activation error: {}", e)
471+
}
472+
} else {
473+
result.with_context(|_| {
474+
"failed to enable HTTP2, is curl not built right?"
475+
})?;
476+
}
477+
} else {
478+
handle.http_version(HttpVersion::V11)?;
460479
}
461480

462481
// This is an option to `libcurl` which indicates that if there's a

src/doc/src/reference/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ timeout = 30 # Timeout for each HTTP request, in seconds
102102
cainfo = "cert.pem" # Path to Certificate Authority (CA) bundle (optional)
103103
check-revoke = true # Indicates whether SSL certs are checked for revocation
104104
low-speed-limit = 5 # Lower threshold for bytes/sec (10 = default, 0 = disabled)
105-
multiplexing = false # whether or not to use HTTP/2 multiplexing where possible
105+
multiplexing = true # whether or not to use HTTP/2 multiplexing where possible
106106

107107
# This setting can be used to help debug what's going on with HTTP requests made
108108
# by Cargo. When set to `true` then Cargo's normal debug logging will be filled

0 commit comments

Comments
 (0)