@@ -70,33 +70,32 @@ macro_rules! impl_store_and_remote_fetch {
7070
7171 #[ cfg( all( not( feature = "wasm" ) , not( target_env = "sgx" ) ) ) ]
7272 fn remote_fetch( buffer: & mut Vec <u8 >, url: & str ) -> Result <( ) , $crate:: errors:: ParameterError > {
73+ use std:: io:: Read ;
74+
7375 #[ cfg( not( feature = "no_std_out" ) ) ]
7476 {
7577 use colored:: * ;
7678 let output = format!( "{:>15} - Downloading \" {}\" " , "Installation" , url) ;
7779 println!( "{}" , output. dimmed( ) ) ;
7880 }
7981
80- let host = url. split( '/' ) . nth( 2 ) . unwrap_or_default( ) . to_string( ) ;
81- let retry_policy = reqwest:: retry:: for_host( host)
82- . max_retries_per_request( 3 )
83- . classify_fn( |req_rep| {
84- if req_rep. error( ) . is_some( ) {
85- return req_rep. retryable( ) ;
82+ // Retry up to 3 times on transient errors (5xx, 429, IO, timeout).
83+ let mut attempts = 3u32 ;
84+ loop {
85+ match ureq:: get( url) . config( ) . max_redirects( 10 ) . build( ) . call( ) {
86+ Ok ( mut response) => {
87+ response. body_mut( ) . as_reader( ) . read_to_end( buffer) ?;
88+ break ;
8689 }
87- match req_rep. status( ) {
88- Some ( status) if status. is_server_error( ) || status. as_u16( ) == 429 => req_rep. retryable( ) ,
89- _ => req_rep. success( ) ,
90+ Err ( ureq:: Error :: StatusCode ( code) ) if attempts > 0 && ( code >= 500 || code == 429 ) => {
91+ attempts -= 1 ;
9092 }
91- } ) ;
92-
93- let client = reqwest:: blocking:: Client :: builder( )
94- . redirect( reqwest:: redirect:: Policy :: limited( 10 ) ) // Limit to 10 redirects.
95- . retry( retry_policy)
96- . build( ) ?;
97-
98- let mut response = client. get( url) . send( ) ?. error_for_status( ) ?;
99- response. copy_to( buffer) ?;
93+ Err ( ureq:: Error :: Io ( _) | ureq:: Error :: Timeout ( _) ) if attempts > 0 => {
94+ attempts -= 1 ;
95+ }
96+ Err ( err) => return Err ( err. into( ) ) ,
97+ }
98+ }
10099
101100 #[ cfg( not( feature = "no_std_out" ) ) ]
102101 {
0 commit comments