From eae650296b32173086f4f28686af033dab02aceb Mon Sep 17 00:00:00 2001 From: Yao Zongyou Date: Sat, 26 Oct 2024 03:09:42 +0800 Subject: [PATCH] feat: add cargo features for tls options (#61) Adds features to switch native-tls, rustls-tls or disable tls at all --- Cargo.toml | 13 +++++++++++-- src/s3/client.rs | 10 ++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e3949ce..0234594 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,17 @@ readme = "README.md" keywords = ["object-storage", "minio", "s3"] categories = ["api-bindings", "web-programming::http-client"] +[dependencies.reqwest] +version = "0.12.5" +default-features = false +features = ["stream"] + +[features] +default = ["default-tls"] +default-tls = ["reqwest/default-tls"] +native-tls = ["reqwest/native-tls"] +rustls-tls = ["reqwest/rustls-tls"] + [dependencies] async-recursion = "1.0.4" async-trait = "0.1.73" @@ -35,7 +46,6 @@ os_info = "3.7.0" percent-encoding = "2.3.0" rand = { version = "0.8.5", features = ["small_rng"] } regex = "1.9.4" -reqwest = { version = "0.12.5", features = ["native-tls", "blocking", "rustls-tls", "stream"] } serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.105" sha2 = "0.10.7" @@ -45,7 +55,6 @@ tokio-util = { version = "0.7.8", features = ["io"] } urlencoding = "2.1.3" xmltree = "0.10.3" - [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes", "tokio1"] } clap = { version = "4.5.4", features = ["derive"] } diff --git a/src/s3/client.rs b/src/s3/client.rs index efc4d63..c1c2771 100644 --- a/src/s3/client.rs +++ b/src/s3/client.rs @@ -120,10 +120,20 @@ impl ClientBuilder { } builder = builder.user_agent(user_agent); + #[cfg(any( + feature = "default-tls", + feature = "native-tls", + feature = "rustls-tls" + ))] if let Some(v) = self.ignore_cert_check { builder = builder.danger_accept_invalid_certs(v); } + #[cfg(any( + feature = "default-tls", + feature = "native-tls", + feature = "rustls-tls" + ))] if let Some(v) = self.ssl_cert_file { let mut buf = Vec::new(); File::open(v)?.read_to_end(&mut buf)?;