diff --git a/tonic/src/transport/server/mod.rs b/tonic/src/transport/server/mod.rs index b05f78049..5fa003afa 100644 --- a/tonic/src/transport/server/mod.rs +++ b/tonic/src/transport/server/mod.rs @@ -90,6 +90,7 @@ pub struct Server { tcp_nodelay: bool, http2_keepalive_interval: Option, http2_keepalive_timeout: Option, + http2_adaptive_window: Option, max_frame_size: Option, accept_http1: bool, service_builder: ServiceBuilder, @@ -110,6 +111,7 @@ impl Default for Server { tcp_nodelay: false, http2_keepalive_interval: None, http2_keepalive_timeout: None, + http2_adaptive_window: None, max_frame_size: None, accept_http1: false, service_builder: Default::default(), @@ -258,6 +260,17 @@ impl Server { } } + /// Sets whether to use an adaptive flow control. Defaults to false. + /// Enabling this will override the limits set in http2_initial_stream_window_size and + /// http2_initial_connection_window_size. + #[must_use] + pub fn http2_adaptive_window(self, enabled: Option) -> Self { + Server { + http2_adaptive_window: enabled, + ..self + } + } + /// Set whether TCP keepalive messages are enabled on accepted connections. /// /// If `None` is specified, keepalive is disabled, otherwise the duration @@ -439,6 +452,7 @@ impl Server { tcp_nodelay: self.tcp_nodelay, http2_keepalive_interval: self.http2_keepalive_interval, http2_keepalive_timeout: self.http2_keepalive_timeout, + http2_adaptive_window: self.http2_adaptive_window, max_frame_size: self.max_frame_size, accept_http1: self.accept_http1, } @@ -476,6 +490,7 @@ impl Server { let http2_keepalive_timeout = self .http2_keepalive_timeout .unwrap_or_else(|| Duration::new(DEFAULT_HTTP2_KEEPALIVE_TIMEOUT_SECS, 0)); + let http2_adaptive_window = self.http2_adaptive_window; let svc = self.service_builder.service(svc); @@ -497,6 +512,7 @@ impl Server { .http2_max_concurrent_streams(max_concurrent_streams) .http2_keep_alive_interval(http2_keepalive_interval) .http2_keep_alive_timeout(http2_keepalive_timeout) + .http2_adaptive_window(http2_adaptive_window.unwrap_or_default()) .http2_max_frame_size(max_frame_size); if let Some(signal) = signal {