11//! Access to a HTTP-based crate registry. See [`HttpRegistry`] for details.
22
33use crate :: core:: { PackageId , SourceId } ;
4- use crate :: ops:: { self } ;
4+ use crate :: ops;
55use crate :: sources:: registry:: download;
66use crate :: sources:: registry:: MaybeLock ;
77use crate :: sources:: registry:: { LoadResponse , RegistryConfig , RegistryData } ;
@@ -11,9 +11,9 @@ use crate::util::network::sleep::SleepTracker;
1111use crate :: util:: { auth, Config , Filesystem , IntoUrl , Progress , ProgressStyle } ;
1212use anyhow:: Context ;
1313use cargo_util:: paths;
14- use curl:: easy:: { Easy , HttpVersion , List } ;
14+ use curl:: easy:: { Easy , List } ;
1515use curl:: multi:: { EasyHandle , Multi } ;
16- use log:: { debug, trace, warn } ;
16+ use log:: { debug, trace} ;
1717use std:: cell:: RefCell ;
1818use std:: collections:: { HashMap , HashSet } ;
1919use std:: fs:: { self , File } ;
@@ -383,7 +383,7 @@ impl<'cfg> HttpRegistry<'cfg> {
383383 }
384384 let config_json_path = self
385385 . assert_index_locked ( & self . index_path )
386- . join ( "config.json" ) ;
386+ . join ( RegistryConfig :: NAME ) ;
387387 match fs:: read ( & config_json_path) {
388388 Ok ( raw_data) => match serde_json:: from_slice ( & raw_data) {
389389 Ok ( json) => {
@@ -404,12 +404,12 @@ impl<'cfg> HttpRegistry<'cfg> {
404404 fn config ( & mut self ) -> Poll < CargoResult < & RegistryConfig > > {
405405 debug ! ( "loading config" ) ;
406406 let index_path = self . assert_index_locked ( & self . index_path ) ;
407- let config_json_path = index_path. join ( "config.json" ) ;
408- if self . is_fresh ( Path :: new ( "config.json" ) ) && self . config_cached ( ) ?. is_some ( ) {
407+ let config_json_path = index_path. join ( RegistryConfig :: NAME ) ;
408+ if self . is_fresh ( Path :: new ( RegistryConfig :: NAME ) ) && self . config_cached ( ) ?. is_some ( ) {
409409 return Poll :: Ready ( Ok ( self . registry_config . as_ref ( ) . unwrap ( ) ) ) ;
410410 }
411411
412- match ready ! ( self . load( Path :: new( "" ) , Path :: new( "config.json" ) , None ) ?) {
412+ match ready ! ( self . load( Path :: new( "" ) , Path :: new( RegistryConfig :: NAME ) , None ) ?) {
413413 LoadResponse :: Data {
414414 raw_data,
415415 index_version : _,
@@ -543,7 +543,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
543543 }
544544 StatusCode :: Unauthorized
545545 if !self . auth_required
546- && path == Path :: new ( "config.json" )
546+ && path == Path :: new ( RegistryConfig :: NAME )
547547 && self . config . cli_unstable ( ) . registry_auth =>
548548 {
549549 debug ! ( "re-attempting request for config.json with authorization included." ) ;
@@ -593,7 +593,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
593593 }
594594 }
595595
596- if path != Path :: new ( "config.json" ) {
596+ if path != Path :: new ( RegistryConfig :: NAME ) {
597597 self . auth_required = ready ! ( self . config( ) ?) . auth_required ;
598598 } else if !self . auth_required {
599599 // Check if there's a cached config that says auth is required.
@@ -618,20 +618,7 @@ impl<'cfg> RegistryData for HttpRegistry<'cfg> {
618618 handle. follow_location ( true ) ?;
619619
620620 // Enable HTTP/2 if possible.
621- if self . multiplexing {
622- crate :: try_old_curl!( handle. http_version( HttpVersion :: V2 ) , "HTTP2" ) ;
623- } else {
624- handle. http_version ( HttpVersion :: V11 ) ?;
625- }
626-
627- // This is an option to `libcurl` which indicates that if there's a
628- // bunch of parallel requests to the same host they all wait until the
629- // pipelining status of the host is known. This means that we won't
630- // initiate dozens of connections to crates.io, but rather only one.
631- // Once the main one is opened we realized that pipelining is possible
632- // and multiplexing is possible with static.crates.io. All in all this
633- // reduces the number of connections done to a more manageable state.
634- crate :: try_old_curl!( handle. pipewait( true ) , "pipewait" ) ;
621+ crate :: try_old_curl_http2_pipewait!( self . multiplexing, handle) ;
635622
636623 let mut headers = List :: new ( ) ;
637624 // Include a header to identify the protocol. This allows the server to
0 commit comments