Skip to content

Commit

Permalink
feat(tonic): expose setting for http2_adaptive_window (#657)
Browse files Browse the repository at this point in the history
Fixes #358
  • Loading branch information
davidpdrsn committed Jun 21, 2021
1 parent 2ba0889 commit 12815d0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tonic/src/transport/channel/endpoint.rs
Expand Up @@ -38,6 +38,7 @@ pub struct Endpoint {
pub(crate) http2_keep_alive_interval: Option<Duration>,
pub(crate) http2_keep_alive_timeout: Option<Duration>,
pub(crate) http2_keep_alive_while_idle: Option<bool>,
pub(crate) http2_adaptive_window: Option<bool>,
}

impl Endpoint {
Expand Down Expand Up @@ -231,6 +232,14 @@ impl Endpoint {
}
}

/// Sets whether to use an adaptive flow control. Uses `hyper`'s default otherwise.
pub fn http2_adaptive_window(self, enabled: bool) -> Self {
Endpoint {
http2_adaptive_window: Some(enabled),
..self
}
}

/// Create a channel from this config.
pub async fn connect(&self) -> Result<Channel, Error> {
let mut http = hyper::client::connect::HttpConnector::new();
Expand Down Expand Up @@ -319,6 +328,7 @@ impl From<Uri> for Endpoint {
http2_keep_alive_interval: None,
http2_keep_alive_timeout: None,
http2_keep_alive_while_idle: None,
http2_adaptive_window: None,
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions tonic/src/transport/service/connection.rs
Expand Up @@ -49,6 +49,10 @@ impl Connection {
settings.http2_keep_alive_while_idle(val);
}

if let Some(val) = endpoint.http2_adaptive_window {
settings.http2_adaptive_window(val);
}

let stack = ServiceBuilder::new()
.layer_fn(|s| AddOrigin::new(s, endpoint.uri.clone()))
.layer_fn(|s| UserAgent::new(s, endpoint.user_agent.clone()))
Expand Down

0 comments on commit 12815d0

Please sign in to comment.