Skip to content

Commit 919d28b

Browse files
adamchalmersAdam Chalmers
and
Adam Chalmers
authored
feat(transport): Expose hyper's H2 adaptive window on server (#1071)
Co-authored-by: Adam Chalmers <[email protected]>
1 parent 2a83f8b commit 919d28b

File tree

1 file changed

+16
-0
lines changed
  • tonic/src/transport/server

1 file changed

+16
-0
lines changed

tonic/src/transport/server/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub struct Server<L = Identity> {
9090
tcp_nodelay: bool,
9191
http2_keepalive_interval: Option<Duration>,
9292
http2_keepalive_timeout: Option<Duration>,
93+
http2_adaptive_window: Option<bool>,
9394
max_frame_size: Option<u32>,
9495
accept_http1: bool,
9596
service_builder: ServiceBuilder<L>,
@@ -110,6 +111,7 @@ impl Default for Server<Identity> {
110111
tcp_nodelay: false,
111112
http2_keepalive_interval: None,
112113
http2_keepalive_timeout: None,
114+
http2_adaptive_window: None,
113115
max_frame_size: None,
114116
accept_http1: false,
115117
service_builder: Default::default(),
@@ -258,6 +260,17 @@ impl<L> Server<L> {
258260
}
259261
}
260262

263+
/// Sets whether to use an adaptive flow control. Defaults to false.
264+
/// Enabling this will override the limits set in http2_initial_stream_window_size and
265+
/// http2_initial_connection_window_size.
266+
#[must_use]
267+
pub fn http2_adaptive_window(self, enabled: Option<bool>) -> Self {
268+
Server {
269+
http2_adaptive_window: enabled,
270+
..self
271+
}
272+
}
273+
261274
/// Set whether TCP keepalive messages are enabled on accepted connections.
262275
///
263276
/// If `None` is specified, keepalive is disabled, otherwise the duration
@@ -439,6 +452,7 @@ impl<L> Server<L> {
439452
tcp_nodelay: self.tcp_nodelay,
440453
http2_keepalive_interval: self.http2_keepalive_interval,
441454
http2_keepalive_timeout: self.http2_keepalive_timeout,
455+
http2_adaptive_window: self.http2_adaptive_window,
442456
max_frame_size: self.max_frame_size,
443457
accept_http1: self.accept_http1,
444458
}
@@ -476,6 +490,7 @@ impl<L> Server<L> {
476490
let http2_keepalive_timeout = self
477491
.http2_keepalive_timeout
478492
.unwrap_or_else(|| Duration::new(DEFAULT_HTTP2_KEEPALIVE_TIMEOUT_SECS, 0));
493+
let http2_adaptive_window = self.http2_adaptive_window;
479494

480495
let svc = self.service_builder.service(svc);
481496

@@ -497,6 +512,7 @@ impl<L> Server<L> {
497512
.http2_max_concurrent_streams(max_concurrent_streams)
498513
.http2_keep_alive_interval(http2_keepalive_interval)
499514
.http2_keep_alive_timeout(http2_keepalive_timeout)
515+
.http2_adaptive_window(http2_adaptive_window.unwrap_or_default())
500516
.http2_max_frame_size(max_frame_size);
501517

502518
if let Some(signal) = signal {

0 commit comments

Comments
 (0)