From eaeb47050819873608e32e1d13df089119ce9815 Mon Sep 17 00:00:00 2001 From: tottoto Date: Wed, 8 Jan 2025 18:02:00 +0900 Subject: [PATCH] chore(channel): Simplify helper to create http connector (#2124) --- tonic/src/transport/channel/endpoint.rs | 14 ++++---------- tonic/src/transport/channel/service/discover.rs | 3 +-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tonic/src/transport/channel/endpoint.rs b/tonic/src/transport/channel/endpoint.rs index 9de93f7cd..07910fe06 100644 --- a/tonic/src/transport/channel/endpoint.rs +++ b/tonic/src/transport/channel/endpoint.rs @@ -325,21 +325,18 @@ impl Endpoint { ) } - pub(crate) fn http_connector(&self) -> HttpConnector { + pub(crate) fn http_connector(&self) -> service::Connector { let mut http = HttpConnector::new(); http.enforce_http(false); http.set_nodelay(self.tcp_nodelay); http.set_keepalive(self.tcp_keepalive); http.set_connect_timeout(self.connect_timeout); - http + self.connector(http) } /// Create a channel from this config. pub async fn connect(&self) -> Result { - let http = self.http_connector(); - let connector = self.connector(http); - - Channel::connect(connector, self.clone()).await + Channel::connect(self.http_connector(), self.clone()).await } /// Create a channel from this config. @@ -347,10 +344,7 @@ impl Endpoint { /// The channel returned by this method does not attempt to connect to the endpoint until first /// use. pub fn connect_lazy(&self) -> Channel { - let http = self.http_connector(); - let connector = self.connector(http); - - Channel::new(connector, self.clone()) + Channel::new(self.http_connector(), self.clone()) } /// Connect with a custom connector. diff --git a/tonic/src/transport/channel/service/discover.rs b/tonic/src/transport/channel/service/discover.rs index 838be3ced..c33f43ba1 100644 --- a/tonic/src/transport/channel/service/discover.rs +++ b/tonic/src/transport/channel/service/discover.rs @@ -36,8 +36,7 @@ impl Stream for DynamicServiceStream { Poll::Pending | Poll::Ready(None) => Poll::Pending, Poll::Ready(Some(change)) => match change { Change::Insert(k, endpoint) => { - let http = endpoint.http_connector(); - let connection = Connection::lazy(endpoint.connector(http), endpoint); + let connection = Connection::lazy(endpoint.http_connector(), endpoint); Poll::Ready(Some(Ok(TowerChange::Insert(k, connection)))) } Change::Remove(k) => Poll::Ready(Some(Ok(TowerChange::Remove(k)))),