From 12815d0a1d558eb9f661a85354336b04df1f5bab Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Mon, 21 Jun 2021 18:42:52 +0200 Subject: [PATCH] feat(tonic): expose setting for `http2_adaptive_window` (#657) Fixes https://github.com/hyperium/tonic/issues/358 --- tonic/src/transport/channel/endpoint.rs | 10 ++++++++++ tonic/src/transport/service/connection.rs | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/tonic/src/transport/channel/endpoint.rs b/tonic/src/transport/channel/endpoint.rs index fb9d0c496..204ab7bc9 100644 --- a/tonic/src/transport/channel/endpoint.rs +++ b/tonic/src/transport/channel/endpoint.rs @@ -38,6 +38,7 @@ pub struct Endpoint { pub(crate) http2_keep_alive_interval: Option, pub(crate) http2_keep_alive_timeout: Option, pub(crate) http2_keep_alive_while_idle: Option, + pub(crate) http2_adaptive_window: Option, } impl Endpoint { @@ -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 { let mut http = hyper::client::connect::HttpConnector::new(); @@ -319,6 +328,7 @@ impl From for Endpoint { http2_keep_alive_interval: None, http2_keep_alive_timeout: None, http2_keep_alive_while_idle: None, + http2_adaptive_window: None, } } } diff --git a/tonic/src/transport/service/connection.rs b/tonic/src/transport/service/connection.rs index 6a365417e..f321f3402 100644 --- a/tonic/src/transport/service/connection.rs +++ b/tonic/src/transport/service/connection.rs @@ -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()))