@@ -14,8 +14,8 @@ use crate::util::{GlobalContext, IntoUrl, MetricsCounter, Progress, network};
1414use anyhow:: { Context as _, anyhow} ;
1515use cargo_util:: { ProcessBuilder , paths} ;
1616use cargo_util_terminal:: Verbosity ;
17+ use curl:: easy:: List ;
1718use git2:: { ErrorClass , ObjectType , Oid } ;
18- use http:: { Request , StatusCode } ;
1919use tracing:: { debug, info} ;
2020use url:: Url ;
2121
@@ -1580,20 +1580,36 @@ fn github_fast_path(
15801580 "https://api.github.com/repos/{}/{}/commits/{}" ,
15811581 username, repository, github_branch_name,
15821582 ) ;
1583+ let mut handle = gctx. http ( ) ?. lock ( ) . unwrap ( ) ;
15831584 debug ! ( "attempting GitHub fast path for {}" , url) ;
1584- let mut request = Request :: get ( url) ;
1585- request = request. header ( http:: header:: ACCEPT , "application/vnd.github.3.sha" ) ;
1586- if let Some ( local_object) = local_object {
1587- request = request. header ( http:: header:: IF_NONE_MATCH , & format ! ( "\" {local_object}\" " ) ) ;
1588- }
1589- let request = request. body ( Vec :: new ( ) ) ?;
1590- let response = crate :: util:: block_on ( gctx. http_async ( ) ?. request ( request) ) ?;
1591- let response_code = response. status ( ) ;
1592- if response_code == StatusCode :: NOT_MODIFIED {
1585+ handle. get ( true ) ?;
1586+ handle. url ( & url) ?;
1587+ handle. useragent ( "cargo" ) ?;
1588+ handle. follow_location ( true ) ?; // follow redirects
1589+ handle. http_headers ( {
1590+ let mut headers = List :: new ( ) ;
1591+ headers. append ( "Accept: application/vnd.github.3.sha" ) ?;
1592+ if let Some ( local_object) = local_object {
1593+ headers. append ( & format ! ( "If-None-Match: \" {}\" " , local_object) ) ?;
1594+ }
1595+ headers
1596+ } ) ?;
1597+
1598+ let mut response_body = Vec :: new ( ) ;
1599+ let mut transfer = handle. transfer ( ) ;
1600+ transfer. write_function ( |data| {
1601+ response_body. extend_from_slice ( data) ;
1602+ Ok ( data. len ( ) )
1603+ } ) ?;
1604+ transfer. perform ( ) ?;
1605+ drop ( transfer) ; // end borrow of handle so that response_code can be called
1606+
1607+ let response_code = handle. response_code ( ) ?;
1608+ if response_code == 304 {
15931609 debug ! ( "github fast path up-to-date" ) ;
15941610 Ok ( FastPathRev :: UpToDate )
1595- } else if response_code == StatusCode :: OK
1596- && let Some ( oid_to_fetch) = rev_to_oid ( str:: from_utf8 ( & response . body ( ) ) ?)
1611+ } else if response_code == 200
1612+ && let Some ( oid_to_fetch) = rev_to_oid ( str:: from_utf8 ( & response_body ) ?)
15971613 {
15981614 // response expected to be a full hash hexstring (40 or 64 chars)
15991615 debug ! ( "github fast path fetch {oid_to_fetch}" ) ;
0 commit comments