@@ -12,6 +12,7 @@ use anyhow::{anyhow, bail, Context, Result};
12
12
use retry:: delay:: { jitter, Fibonacci } ;
13
13
use retry:: { retry, OperationResult } ;
14
14
use sha2:: Sha256 ;
15
+ use tracing:: info;
15
16
use url:: Url ;
16
17
17
18
use crate :: errors:: * ;
@@ -246,28 +247,47 @@ async fn download_file_(
246
247
// Download the file
247
248
248
249
// Keep the curl env var around for a bit
249
- let use_curl_backend = process
250
- . var_os ( "RUSTUP_USE_CURL" )
251
- . is_some_and ( |it| it != "0" ) ;
252
- let use_rustls = process
253
- . var_os ( "RUSTUP_USE_RUSTLS" )
254
- . is_none_or ( |it| it != "0" ) ;
255
- let backend = if use_curl_backend {
256
- Backend :: Curl
257
- } else {
258
- let tls_backend = if use_rustls {
259
- TlsBackend :: Rustls
260
- } else {
261
- #[ cfg( feature = "reqwest-native-tls" ) ]
262
- {
263
- TlsBackend :: NativeTls
250
+ let use_curl_backend = process. var_os ( "RUSTUP_USE_CURL" ) . map ( |it| it != "0" ) ;
251
+ let use_rustls = process. var_os ( "RUSTUP_USE_RUSTLS" ) . map ( |it| it != "0" ) ;
252
+
253
+ let backend = match ( use_curl_backend, use_rustls) {
254
+ // If environment specifies a backend that's unavailable, error out
255
+ #[ cfg( not( feature = "reqwest-rustls-tls" ) ) ]
256
+ ( _, Some ( true ) ) => {
257
+ return Err ( anyhow ! (
258
+ "RUSTUP_USE_RUSTLS is set, but this rustup distribution was not built with the reqwest-rustls-tls feature"
259
+ ) ) ;
260
+ }
261
+ #[ cfg( not( feature = "reqwest-native-tls" ) ) ]
262
+ ( _, Some ( false ) ) => {
263
+ return Err ( anyhow ! (
264
+ "RUSTUP_USE_RUSTLS is set to false, but this rustup distribution was not built with the reqwest-native-tls feature"
265
+ ) ) ;
266
+ }
267
+ #[ cfg( not( feature = "curl-backend" ) ) ]
268
+ ( Some ( true ) , _) => {
269
+ return Err ( anyhow ! (
270
+ "RUSTUP_USE_CURL is set, but this rustup distribution was not built with the curl-backend feature"
271
+ ) ) ;
272
+ }
273
+ #[ cfg( feature = "curl-backend" ) ]
274
+ ( Some ( true ) , None ) => Backend :: Curl ,
275
+ #[ cfg( feature = "reqwest-native-tls" ) ]
276
+ ( _, Some ( false ) ) => {
277
+ if use_curl_backend == Some ( true ) {
278
+ info ! ( "RUSTUP_USE_CURL is set and RUSTUP_USE_RUSTLS is set to off, using reqwest with native-tls" ) ;
264
279
}
265
- #[ cfg( not( feature = "reqwest-native-tls" ) ) ]
266
- {
267
- TlsBackend :: Rustls
280
+ Backend :: Reqwest ( TlsBackend :: NativeTls )
281
+ }
282
+ #[ cfg( feature = "reqwest-rustls-tls" ) ]
283
+ ( _, Some ( true ) | None ) => {
284
+ if use_curl_backend == Some ( true ) {
285
+ info ! (
286
+ "both RUSTUP_USE_CURL and RUSTUP_USE_RUSTLS are set, using reqwest with rustls"
287
+ ) ;
268
288
}
269
- } ;
270
- Backend :: Reqwest ( tls_backend )
289
+ Backend :: Reqwest ( TlsBackend :: Rustls )
290
+ }
271
291
} ;
272
292
273
293
notify_handler ( match backend {
0 commit comments