From dcb75a01a6da7ff38c178a2f48ba3d9182c2a324 Mon Sep 17 00:00:00 2001 From: "vigneshwar.sm" Date: Fri, 11 Apr 2025 20:12:05 +0530 Subject: [PATCH 1/2] fix: tls config overwrite in endpoint PR #1866 fixed the breaking change introduced in #1731, but resets the TLS config without checking if `tls` is set. This patch resolves the regression and restores expected behaviour. --- tonic/src/transport/channel/endpoint.rs | 2 +- tonic/src/transport/channel/tls.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tonic/src/transport/channel/endpoint.rs b/tonic/src/transport/channel/endpoint.rs index 3a919e93d..99ff11e9f 100644 --- a/tonic/src/transport/channel/endpoint.rs +++ b/tonic/src/transport/channel/endpoint.rs @@ -62,7 +62,7 @@ impl Endpoint { let me = dst.try_into().map_err(|e| Error::from_source(e.into()))?; #[cfg(feature = "_tls-any")] if let EndpointType::Uri(uri) = &me.uri { - if uri.scheme() == Some(&http::uri::Scheme::HTTPS) { + if me.tls.is_none() && uri.scheme() == Some(&http::uri::Scheme::HTTPS) { return me.tls_config(ClientTlsConfig::new().with_enabled_roots()); } } diff --git a/tonic/src/transport/channel/tls.rs b/tonic/src/transport/channel/tls.rs index 945384fd2..8041187ea 100644 --- a/tonic/src/transport/channel/tls.rs +++ b/tonic/src/transport/channel/tls.rs @@ -113,11 +113,13 @@ impl ClientTlsConfig { /// Activates all TLS roots enabled through `tls-*-roots` feature flags pub fn with_enabled_roots(self) -> Self { - let config = ClientTlsConfig::new(); + let config = self; + #[cfg(feature = "tls-native-roots")] let config = config.with_native_roots(); #[cfg(feature = "tls-webpki-roots")] let config = config.with_webpki_roots(); + config } From f02125ca32a36fd1d4d73ce5ccfdaacfaa21d090 Mon Sep 17 00:00:00 2001 From: "vigneshwar.sm" Date: Fri, 11 Apr 2025 20:22:20 +0530 Subject: [PATCH 2/2] fix: cargo fmt whitespace check --- tonic/src/transport/channel/tls.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tonic/src/transport/channel/tls.rs b/tonic/src/transport/channel/tls.rs index 8041187ea..59ecc36fd 100644 --- a/tonic/src/transport/channel/tls.rs +++ b/tonic/src/transport/channel/tls.rs @@ -114,12 +114,12 @@ impl ClientTlsConfig { /// Activates all TLS roots enabled through `tls-*-roots` feature flags pub fn with_enabled_roots(self) -> Self { let config = self; - + #[cfg(feature = "tls-native-roots")] let config = config.with_native_roots(); #[cfg(feature = "tls-webpki-roots")] let config = config.with_webpki_roots(); - + config }