Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable HTTP/2 by default #6271

Merged
merged 1 commit into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ bytesize = "1.0"
crates-io = { path = "src/crates-io", version = "0.21" }
crossbeam-utils = "0.5"
crypto-hash = "0.3.1"
curl = { version = "0.4.17", features = ['http2'] }
curl-sys = "0.4.12"
curl = { version = "0.4.19", features = ['http2'] }
curl-sys = "0.4.15"
env_logger = "0.5.11"
failure = "0.1.2"
filetime = "0.2"
Expand Down
35 changes: 27 additions & 8 deletions src/cargo/core/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ use std::path::{Path, PathBuf};
use std::time::{Instant, Duration};

use bytesize::ByteSize;
use curl;
use curl_sys;
use curl::easy::{Easy, HttpVersion};
use curl::multi::{Multi, EasyHandle};
use curl;
use curl_sys;
use failure::ResultExt;
use lazycell::LazyCell;
use semver::Version;
use serde::ser;
Expand Down Expand Up @@ -333,7 +334,7 @@ impl<'cfg> PackageSet<'cfg> {
// proxies.
let mut multi = Multi::new();
let multiplexing = config.get::<Option<bool>>("http.multiplexing")?
.unwrap_or(false);
.unwrap_or(true);
multi.pipelining(false, multiplexing)
.chain_err(|| "failed to enable multiplexing/pipelining in curl")?;

Expand Down Expand Up @@ -452,12 +453,30 @@ impl<'a, 'cfg> Downloads<'a, 'cfg> {
handle.follow_location(true)?; // follow redirects

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

// This is an option to `libcurl` which indicates that if there's a
Expand Down
2 changes: 1 addition & 1 deletion src/doc/src/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ timeout = 30 # Timeout for each HTTP request, in seconds
cainfo = "cert.pem" # Path to Certificate Authority (CA) bundle (optional)
check-revoke = true # Indicates whether SSL certs are checked for revocation
low-speed-limit = 5 # Lower threshold for bytes/sec (10 = default, 0 = disabled)
multiplexing = false # whether or not to use HTTP/2 multiplexing where possible
multiplexing = true # whether or not to use HTTP/2 multiplexing where possible

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