Skip to content

Commit a167778

Browse files
fix: tls config overwrite in endpoint
PR hyperium#1866 fixed the breaking change introduced in hyperium#1731, but resets the `tls_config` instead of adding the tls roots to existing config. This patch resolves the regression and also restores expected behaviour.
1 parent 13b9643 commit a167778

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

tonic/src/transport/channel/endpoint.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,6 @@ impl Endpoint {
6060
D::Error: Into<crate::BoxError>,
6161
{
6262
let me = dst.try_into().map_err(|e| Error::from_source(e.into()))?;
63-
#[cfg(feature = "_tls-any")]
64-
if let EndpointType::Uri(uri) = &me.uri {
65-
if uri.scheme() == Some(&http::uri::Scheme::HTTPS) {
66-
return me.tls_config(ClientTlsConfig::new().with_enabled_roots());
67-
}
68-
}
6963
Ok(me)
7064
}
7165

@@ -332,14 +326,22 @@ impl Endpoint {
332326
#[cfg(feature = "_tls-any")]
333327
pub fn tls_config(self, tls_config: ClientTlsConfig) -> Result<Self, Error> {
334328
match &self.uri {
335-
EndpointType::Uri(uri) => Ok(Endpoint {
336-
tls: Some(
337-
tls_config
338-
.into_tls_connector(uri)
339-
.map_err(Error::from_source)?,
340-
),
341-
..self
342-
}),
329+
EndpointType::Uri(uri) => {
330+
let mut tls_config = tls_config;
331+
#[cfg(feature = "_tls-any")]
332+
if uri.scheme() == Some(&http::uri::Scheme::HTTPS) {
333+
tls_config = tls_config.with_enabled_roots();
334+
}
335+
336+
Ok(Endpoint {
337+
tls: Some(
338+
tls_config
339+
.into_tls_connector(uri)
340+
.map_err(Error::from_source)?,
341+
),
342+
..self
343+
})
344+
}
343345
EndpointType::Uds(_) => Err(Error::new(error::Kind::InvalidTlsConfigForUds)),
344346
}
345347
}

tonic/src/transport/channel/tls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,13 @@ impl ClientTlsConfig {
113113

114114
/// Activates all TLS roots enabled through `tls-*-roots` feature flags
115115
pub fn with_enabled_roots(self) -> Self {
116-
let config = ClientTlsConfig::new();
116+
let config = self;
117+
117118
#[cfg(feature = "tls-native-roots")]
118119
let config = config.with_native_roots();
119120
#[cfg(feature = "tls-webpki-roots")]
120121
let config = config.with_webpki_roots();
122+
121123
config
122124
}
123125

0 commit comments

Comments
 (0)