@@ -20,20 +20,51 @@ impl<T> PollExt<T> for Poll<T> {
2020 }
2121}
2222
23- // When dynamically linked against libcurl, we want to ignore some failures
24- // when using old versions that don't support certain features.
23+ /// When dynamically linked against libcurl, we want to ignore some failures
24+ /// when using old versions that don't support certain features.
2525#[ macro_export]
2626macro_rules! try_old_curl {
2727 ( $e: expr, $msg: expr) => {
2828 let result = $e;
2929 if cfg!( target_os = "macos" ) {
3030 if let Err ( e) = result {
31- warn!( "ignoring libcurl {} error: {}" , $msg, e) ;
31+ :: log :: warn!( "ignoring libcurl {} error: {}" , $msg, e) ;
3232 }
3333 } else {
34+ use :: anyhow:: Context ;
3435 result. with_context( || {
35- anyhow:: format_err!( "failed to enable {}, is curl not built right?" , $msg)
36+ :: anyhow:: format_err!( "failed to enable {}, is curl not built right?" , $msg)
3637 } ) ?;
3738 }
3839 } ;
3940}
41+
42+ /// Enable HTTP/2 and pipewait to be used as it'll allow true multiplexing
43+ /// which makes downloads much faster.
44+ ///
45+ /// Currently Cargo requests the `http2` feature of the `curl` crate which
46+ /// means it should always be built in. On OSX, however, we ship cargo still
47+ /// linked against the system libcurl. Building curl with ALPN support for
48+ /// HTTP/2 requires newer versions of OSX (the SecureTransport API) than we
49+ /// want to ship Cargo for. By linking Cargo against the system libcurl then
50+ /// older curl installations won't use HTTP/2 but newer ones will. All that to
51+ /// basically say we ignore errors here on OSX, but consider this a fatal error
52+ /// to not activate HTTP/2 on all other platforms.
53+ ///
54+ /// `pipewait` is an option which indicates that if there's a bunch of parallel
55+ /// requests to the same host they all wait until the pipelining status of the
56+ /// host is known. This means that we won't initiate dozens of connections but
57+ /// rather only one. Once the main one is opened we realized that pipelining is
58+ /// possible and multiplexing is possible. All in all this reduces the number
59+ /// of connections down to a more manageable state.
60+ #[ macro_export]
61+ macro_rules! try_old_curl_http2_pipewait {
62+ ( $multiplexing: expr, $handle: expr) => {
63+ if $multiplexing {
64+ $crate:: try_old_curl!( $handle. http_version( curl:: easy:: HttpVersion :: V2 ) , "HTTP/2" ) ;
65+ } else {
66+ $handle. http_version( curl:: easy:: HttpVersion :: V11 ) ?;
67+ }
68+ $crate:: try_old_curl!( $handle. pipewait( true ) , "pipewait" ) ;
69+ } ;
70+ }
0 commit comments