Skip to content

Commit 0d80650

Browse files
committed
tests: inline tls_config() helper
And avoid unused code warnings for redundant verifier configs.
1 parent 2119f9c commit 0d80650

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ webpki-roots = { version = "0.26", optional = true }
3838
futures-util = { version = "0.3", default-features = false }
3939

4040
[dev-dependencies]
41+
cfg-if = "1"
4142
http-body-util = "0.1"
4243
hyper-util = { version = "0.1", default-features = false, features = ["server-auto"] }
4344
rustls = { version = "0.23", default-features = false, features = ["tls12"] }

src/connector.rs

+13-19
Original file line numberDiff line numberDiff line change
@@ -245,29 +245,23 @@ mod tests {
245245
assert_eq!(message, "unsupported scheme http");
246246
}
247247

248-
fn tls_config() -> rustls::ClientConfig {
249-
#[cfg(feature = "rustls-platform-verifier")]
250-
return rustls::ClientConfig::builder()
251-
.with_platform_verifier()
252-
.with_no_client_auth();
253-
254-
#[cfg(feature = "rustls-native-certs")]
255-
return rustls::ClientConfig::builder()
256-
.with_native_roots()
257-
.unwrap()
258-
.with_no_client_auth();
259-
260-
#[cfg(feature = "webpki-roots")]
261-
return rustls::ClientConfig::builder()
262-
.with_webpki_roots()
263-
.with_no_client_auth();
264-
}
265-
266248
async fn connect(
267249
https_only: bool,
268250
https: bool,
269251
) -> Result<MaybeHttpsStream<TokioIo<TcpStream>>, BoxError> {
270-
let builder = HttpsConnectorBuilder::new().with_tls_config(tls_config());
252+
let config_builder = rustls::ClientConfig::builder();
253+
cfg_if::cfg_if! {
254+
if #[cfg(feature = "rustls-platform-verifier")] {
255+
let config_builder = config_builder.with_platform_verifier();
256+
} else if #[cfg(feature = "rustls-native-certs")] {
257+
let config_builder = config_builder.with_native_roots().unwrap();
258+
} else if #[cfg(feature = "webpki-roots")] {
259+
let config_builder = config_builder.with_webpki_roots();
260+
}
261+
}
262+
let config = config_builder.with_no_client_auth();
263+
264+
let builder = HttpsConnectorBuilder::new().with_tls_config(config);
271265
let mut service = match https_only {
272266
true => builder.https_only(),
273267
false => builder.https_or_http(),

0 commit comments

Comments
 (0)