Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(channel): Add helper to create http connector #2121

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,18 @@ impl Endpoint {
)
}

/// Create a channel from this config.
pub async fn connect(&self) -> Result<Channel, Error> {
pub(crate) fn http_connector(&self) -> 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
}

/// 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
Expand All @@ -343,12 +347,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 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);

let http = self.http_connector();
let connector = self.connector(http);

Channel::new(connector, self.clone())
Expand Down
8 changes: 1 addition & 7 deletions tonic/src/transport/channel/service/discover.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::super::{Connection, Endpoint};

use hyper_util::client::legacy::connect::HttpConnector;
use std::{
hash::Hash,
pin::Pin,
Expand Down Expand Up @@ -38,12 +37,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 mut http = HttpConnector::new();
http.set_nodelay(endpoint.tcp_nodelay);
http.set_keepalive(endpoint.tcp_keepalive);
http.set_connect_timeout(endpoint.connect_timeout);
http.enforce_http(false);

let http = endpoint.http_connector();
let connection = Connection::lazy(endpoint.connector(http), endpoint);
let change = Ok(TowerChange::Insert(k, connection));
Poll::Ready(Some(change))
Expand Down
Loading