Skip to content

Commit

Permalink
Simplified Endpoint::new initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Aug 19, 2024
1 parent 55bb186 commit 8688bf9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
18 changes: 3 additions & 15 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use super::Channel;
use super::ClientTlsConfig;
use crate::transport::Error;
use bytes::Bytes;
use http::uri::Scheme;

Check failure on line 9 in tonic/src/transport/channel/endpoint.rs

View workflow job for this annotation

GitHub Actions / check (ubuntu-latest)

unused import: `http::uri::Scheme`

Check failure on line 9 in tonic/src/transport/channel/endpoint.rs

View workflow job for this annotation

GitHub Actions / Interop Tests (ubuntu-latest)

unused import: `http::uri::Scheme`

Check failure on line 9 in tonic/src/transport/channel/endpoint.rs

View workflow job for this annotation

GitHub Actions / Check MSRV

unused import: `http::uri::Scheme`

Check failure on line 9 in tonic/src/transport/channel/endpoint.rs

View workflow job for this annotation

GitHub Actions / Interop Tests (macOS-latest)

unused import: `http::uri::Scheme`

Check failure on line 9 in tonic/src/transport/channel/endpoint.rs

View workflow job for this annotation

GitHub Actions / check (macOS-latest)

unused import: `http::uri::Scheme`

Check failure on line 9 in tonic/src/transport/channel/endpoint.rs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

unused import: `http::uri::Scheme`

Check failure on line 9 in tonic/src/transport/channel/endpoint.rs

View workflow job for this annotation

GitHub Actions / test (macOS-latest)

unused import: `http::uri::Scheme`
use http::{uri::Uri, HeaderValue};
use hyper::rt;
use hyper_util::client::legacy::connect::HttpConnector;
Expand Down Expand Up @@ -50,21 +51,8 @@ impl Endpoint {
{
let me = dst.try_into().map_err(|e| Error::from_source(e.into()))?;
#[cfg(feature = "tls")]
if let Some(tls_config) = me
.uri
.scheme()
.map(|s| s.as_str() == http::uri::Scheme::HTTPS.as_str())
.unwrap_or(false)
.then(|| {
let config = ClientTlsConfig::new();
#[cfg(feature = "tls-native-roots")]
let config = config.with_native_roots();
#[cfg(feature = "tls-webpki-roots")]
let config = config.with_webpki_roots();
config
})
{
return me.tls_config(tls_config);
if me.uri.scheme() == Some(&http::uri::Scheme::HTTPS) {
return me.tls_config(ClientTlsConfig::new().with_enabled_roots());
}

Ok(me)
Expand Down
10 changes: 10 additions & 0 deletions tonic/src/transport/channel/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ impl ClientTlsConfig {
}
}

/// Activates all TLS roots enabled through `tls-*-roots` feature flags
pub fn with_enabled_roots(self) -> Self {
let config = ClientTlsConfig::new();
#[cfg(feature = "tls-native-roots")]
let config = config.with_native_roots();
#[cfg(feature = "tls-webpki-roots")]
let config = config.with_webpki_roots();
config
}

pub(crate) fn into_tls_connector(self, uri: &Uri) -> Result<TlsConnector, crate::Error> {
let domain = match &self.domain {
Some(domain) => domain,
Expand Down

0 comments on commit 8688bf9

Please sign in to comment.