Skip to content

Commit

Permalink
chore(channel): Simplify helper to create http connector (#2124)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto authored Jan 8, 2025
1 parent b4d9195 commit eaeb470
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
14 changes: 4 additions & 10 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,32 +325,26 @@ impl Endpoint {
)
}

pub(crate) fn http_connector(&self) -> HttpConnector {
pub(crate) fn http_connector(&self) -> service::Connector<HttpConnector> {
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<Channel, Error> {
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.
///
/// 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.
Expand Down
3 changes: 1 addition & 2 deletions tonic/src/transport/channel/service/discover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ impl<K: Hash + Eq + Clone> Stream for DynamicServiceStream<K> {
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)))),
Expand Down

0 comments on commit eaeb470

Please sign in to comment.