Skip to content

Commit

Permalink
feat(transport): add max http2 frame size to server. (#529)
Browse files Browse the repository at this point in the history
* tonic: add max http2 frame size to server.

Exposes option to configure the max http2 frame size used by the
underlying hyper server via the `tonic::transport::Server` builder.

Refs: #264

* fix http2_* methods broken in merge conflict
  • Loading branch information
Cameron committed Jan 15, 2021
1 parent 41c51f1 commit 31936e0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct Server {
tcp_nodelay: bool,
http2_keepalive_interval: Option<Duration>,
http2_keepalive_timeout: Option<Duration>,
max_frame_size: Option<u32>,
}

/// A stack based `Service` router.
Expand Down Expand Up @@ -278,6 +279,18 @@ impl Server {
}
}

/// Sets the maximum frame size to use for HTTP2.
///
/// Passing `None` will do nothing.
///
/// If not set, will default from underlying transport.
pub fn max_frame_size(self, frame_size: impl Into<Option<u32>>) -> Self {
Server {
max_frame_size: frame_size.into(),
..self
}
}

/// Intercept inbound headers and add a [`tracing::Span`] to each response future.
pub fn trace_fn<F>(self, f: F) -> Self
where
Expand Down Expand Up @@ -355,6 +368,8 @@ impl Server {
let init_stream_window_size = self.init_stream_window_size;
let max_concurrent_streams = self.max_concurrent_streams;
let timeout = self.timeout;
let max_frame_size = self.max_frame_size;

let http2_keepalive_interval = self.http2_keepalive_interval;
let http2_keepalive_timeout = self
.http2_keepalive_timeout
Expand All @@ -376,7 +391,8 @@ impl Server {
.http2_initial_stream_window_size(init_stream_window_size)
.http2_max_concurrent_streams(max_concurrent_streams)
.http2_keep_alive_interval(http2_keepalive_interval)
.http2_keep_alive_timeout(http2_keepalive_timeout);
.http2_keep_alive_timeout(http2_keepalive_timeout)
.http2_max_frame_size(max_frame_size);

if let Some(signal) = signal {
server
Expand Down

0 comments on commit 31936e0

Please sign in to comment.