Skip to content

Commit

Permalink
tls feature flag for Endpoint::new
Browse files Browse the repository at this point in the history
  • Loading branch information
mkatychev committed Aug 9, 2024
1 parent 7f46d3a commit 03913b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/integration_tests/tests/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl test_server::Test for Svc {
#[tokio::test]
async fn connect_returns_err() {
let res = TestClient::connect("http://thisdoesntexist").await;
dbg!(&res);

assert!(res.is_err());
}
Expand Down
18 changes: 18 additions & 0 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ impl Endpoint {
D::Error: Into<crate::Error>,
{
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);
}

Ok(me)
}

Expand Down

0 comments on commit 03913b9

Please sign in to comment.