From 676c97426ef95c0b04396f8da1a08ef82e3aef15 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 17 Jun 2024 10:31:01 +0200 Subject: [PATCH 1/2] Inline small errors module --- download/src/errors.rs | 21 ------------------- download/src/lib.rs | 46 +++++++++++++++++++++++++----------------- 2 files changed, 28 insertions(+), 39 deletions(-) delete mode 100644 download/src/errors.rs diff --git a/download/src/errors.rs b/download/src/errors.rs deleted file mode 100644 index 37d50a1bf3..0000000000 --- a/download/src/errors.rs +++ /dev/null @@ -1,21 +0,0 @@ -use thiserror::Error; - -#[derive(Debug, Error)] -pub enum DownloadError { - #[error("http request returned an unsuccessful status code: {0}")] - HttpStatus(u32), - #[error("file not found")] - FileNotFound, - #[error("download backend '{0}' unavailable")] - BackendUnavailable(&'static str), - #[error("{0}")] - Message(String), - #[error(transparent)] - IoError(#[from] std::io::Error), - #[cfg(feature = "reqwest-backend")] - #[error(transparent)] - Reqwest(#[from] ::reqwest::Error), - #[cfg(feature = "curl-backend")] - #[error(transparent)] - CurlError(#[from] curl::Error), -} diff --git a/download/src/lib.rs b/download/src/lib.rs index 8c2f9892cc..e493ac8f33 100644 --- a/download/src/lib.rs +++ b/download/src/lib.rs @@ -1,16 +1,14 @@ //! Easy file downloading #![deny(rust_2018_idioms)] +use std::fs::remove_file; use std::path::Path; use anyhow::Context; pub use anyhow::Result; -use std::fs::remove_file; +use thiserror::Error; use url::Url; -mod errors; -pub use crate::errors::*; - /// User agent header value for HTTP request. /// See: https://github.com/rust-lang/rustup/issues/2860. #[cfg(feature = "curl-backend")] @@ -185,8 +183,7 @@ pub mod curl { use curl::easy::Easy; use url::Url; - use super::Event; - use crate::errors::*; + use super::{DownloadError, Event}; pub fn download( url: &Url, @@ -306,9 +303,7 @@ pub mod reqwest_be { use tokio_stream::StreamExt; use url::Url; - use super::Event; - use super::TlsBackend; - use crate::errors::*; + use super::{DownloadError, Event, TlsBackend}; pub async fn download( url: &Url, @@ -460,15 +455,33 @@ pub mod reqwest_be { } } +#[derive(Debug, Error)] +pub enum DownloadError { + #[error("http request returned an unsuccessful status code: {0}")] + HttpStatus(u32), + #[error("file not found")] + FileNotFound, + #[error("download backend '{0}' unavailable")] + BackendUnavailable(&'static str), + #[error("{0}")] + Message(String), + #[error(transparent)] + IoError(#[from] std::io::Error), + #[cfg(feature = "reqwest-backend")] + #[error(transparent)] + Reqwest(#[from] ::reqwest::Error), + #[cfg(feature = "curl-backend")] + #[error(transparent)] + CurlError(#[from] ::curl::Error), +} + #[cfg(not(feature = "curl-backend"))] pub mod curl { - use anyhow::{anyhow, Result}; - - use super::Event; - use crate::errors::*; use url::Url; + use super::{DownloadError, Event}; + pub fn download( _url: &Url, _resume_from: u64, @@ -480,14 +493,11 @@ pub mod curl { #[cfg(not(feature = "reqwest-backend"))] pub mod reqwest_be { - use anyhow::{anyhow, Result}; - - use super::Event; - use super::TlsBackend; - use crate::errors::*; use url::Url; + use super::{DownloadError, Event, TlsBackend}; + pub fn download( _url: &Url, _resume_from: u64, From aa4b455a2b4559df949ed75880cd55575bddb8f8 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 17 Jun 2024 10:37:12 +0200 Subject: [PATCH 2/2] Rename default-tls to native-tls --- Cargo.toml | 4 ++-- ci/run.bash | 4 ++-- download/Cargo.toml | 6 ++---- download/src/lib.rs | 18 +++++++++--------- download/tests/download-reqwest-resume.rs | 4 ++-- src/utils/utils.rs | 6 +++--- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 54f13a0a72..8c992eb2d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,14 +15,14 @@ curl-backend = ["download/curl-backend"] default = [ "curl-backend", "reqwest-backend", - "reqwest-default-tls", + "reqwest-native-tls", "reqwest-rustls-tls", ] reqwest-backend = ["download/reqwest-backend"] vendored-openssl = ['openssl/vendored'] -reqwest-default-tls = ["download/reqwest-default-tls"] +reqwest-native-tls = ["download/reqwest-native-tls"] reqwest-rustls-tls = ["download/reqwest-rustls-tls"] # Include in the default set to disable self-update and uninstall. diff --git a/ci/run.bash b/ci/run.bash index 0bab531617..c83bf5e758 100644 --- a/ci/run.bash +++ b/ci/run.bash @@ -8,7 +8,7 @@ rustc -vV cargo -vV -FEATURES=('--no-default-features' '--features' 'curl-backend,reqwest-backend,reqwest-default-tls') +FEATURES=('--no-default-features' '--features' 'curl-backend,reqwest-backend,reqwest-native-tls') case "$(uname -s)" in *NT* ) ;; # Windows NT * ) FEATURES+=('--features' 'vendored-openssl') ;; @@ -38,7 +38,7 @@ target_cargo() { target_cargo build download_pkg_test() { - features=('--no-default-features' '--features' 'curl-backend,reqwest-backend,reqwest-default-tls') + features=('--no-default-features' '--features' 'curl-backend,reqwest-backend,reqwest-native-tls') case "$TARGET" in # these platforms aren't supported by ring: powerpc* ) ;; diff --git a/download/Cargo.toml b/download/Cargo.toml index a431c0c483..4f89af8735 100644 --- a/download/Cargo.toml +++ b/download/Cargo.toml @@ -5,12 +5,10 @@ edition = "2021" license = "MIT OR Apache-2.0" [features] - -default = ["reqwest-backend", "reqwest-rustls-tls", "reqwest-default-tls"] - +default = ["reqwest-backend", "reqwest-rustls-tls", "reqwest-native-tls"] curl-backend = ["curl"] reqwest-backend = ["reqwest", "env_proxy"] -reqwest-default-tls = ["reqwest/default-tls", "dep:once_cell"] +reqwest-native-tls = ["reqwest/native-tls", "dep:once_cell"] reqwest-rustls-tls = ["reqwest/rustls-tls-native-roots", "dep:once_cell"] [dependencies] diff --git a/download/src/lib.rs b/download/src/lib.rs index e493ac8f33..0bed7b36b4 100644 --- a/download/src/lib.rs +++ b/download/src/lib.rs @@ -14,7 +14,7 @@ use url::Url; #[cfg(feature = "curl-backend")] const CURL_USER_AGENT: &str = concat!("rustup/", env!("CARGO_PKG_VERSION"), " (curl)"); -#[cfg(feature = "reqwest-default-tls")] +#[cfg(feature = "reqwest-native-tls")] const REQWEST_DEFAULT_TLS_USER_AGENT: &str = concat!( "rustup/", env!("CARGO_PKG_VERSION"), @@ -34,7 +34,7 @@ pub enum Backend { #[derive(Debug, Copy, Clone)] pub enum TlsBackend { Rustls, - Default, + NativeTls, } #[derive(Debug, Copy, Clone)] @@ -289,7 +289,7 @@ pub mod curl { pub mod reqwest_be { #[cfg(all( not(feature = "reqwest-rustls-tls"), - not(feature = "reqwest-default-tls") + not(feature = "reqwest-native-tls") ))] compile_error!("Must select a reqwest TLS backend"); @@ -297,7 +297,7 @@ pub mod reqwest_be { use std::time::Duration; use anyhow::{anyhow, Context, Result}; - #[cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-default-tls"))] + #[cfg(any(feature = "reqwest-rustls-tls", feature = "reqwest-native-tls"))] use once_cell::sync::Lazy; use reqwest::{header, Client, ClientBuilder, Proxy, Response}; use tokio_stream::StreamExt; @@ -367,7 +367,7 @@ pub mod reqwest_be { catcher().unwrap() }); - #[cfg(feature = "reqwest-default-tls")] + #[cfg(feature = "reqwest-native-tls")] static CLIENT_DEFAULT_TLS: Lazy = Lazy::new(|| { let catcher = || { client_generic() @@ -400,10 +400,10 @@ pub mod reqwest_be { TlsBackend::Rustls => { return Err(DownloadError::BackendUnavailable("reqwest rustls")); } - #[cfg(feature = "reqwest-default-tls")] - TlsBackend::Default => &CLIENT_DEFAULT_TLS, - #[cfg(not(feature = "reqwest-default-tls"))] - TlsBackend::Default => { + #[cfg(feature = "reqwest-native-tls")] + TlsBackend::NativeTls => &CLIENT_DEFAULT_TLS, + #[cfg(not(feature = "reqwest-native-tls"))] + TlsBackend::NativeTls => { return Err(DownloadError::BackendUnavailable("reqwest default TLS")); } }; diff --git a/download/tests/download-reqwest-resume.rs b/download/tests/download-reqwest-resume.rs index 189e078f0f..dec87a8ce1 100644 --- a/download/tests/download-reqwest-resume.rs +++ b/download/tests/download-reqwest-resume.rs @@ -21,7 +21,7 @@ async fn resume_partial_from_file_url() { let from_url = Url::from_file_path(&from_path).unwrap(); download_to_path_with_backend( - Backend::Reqwest(TlsBackend::Default), + Backend::Reqwest(TlsBackend::NativeTls), &from_url, &target_path, true, @@ -48,7 +48,7 @@ async fn callback_gets_all_data_as_if_the_download_happened_all_at_once() { let received_in_callback = Mutex::new(Vec::new()); download_to_path_with_backend( - Backend::Reqwest(TlsBackend::Default), + Backend::Reqwest(TlsBackend::NativeTls), &from_url, &target_path, true, diff --git a/src/utils/utils.rs b/src/utils/utils.rs index 1452de69a2..a4b974f575 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -229,11 +229,11 @@ async fn download_file_( let tls_backend = if use_rustls { TlsBackend::Rustls } else { - #[cfg(feature = "reqwest-default-tls")] + #[cfg(feature = "reqwest-native-tls")] { - TlsBackend::Default + TlsBackend::NativeTls } - #[cfg(not(feature = "reqwest-default-tls"))] + #[cfg(not(feature = "reqwest-native-tls"))] { TlsBackend::Rustls }