Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: allow setting max_header_list_size #1870

Merged
merged 2 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tonic/src/transport/channel/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ impl Endpoint {
}
}

/// Sets the max header list size. Uses `hyper`'s default otherwise.
/// Sets the max size of received header frames.
///
/// This will default to whatever the default in hyper is. As of v1.4.1, it is 16 KiB.
pub fn http2_max_header_list_size(self, size: u32) -> Self {
Endpoint {
http2_max_header_list_size: Some(size),
Expand Down
19 changes: 19 additions & 0 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct Server<L = Identity> {
http2_keepalive_timeout: Option<Duration>,
http2_adaptive_window: Option<bool>,
http2_max_pending_accept_reset_streams: Option<usize>,
http2_max_header_list_size: Option<u32>,
max_frame_size: Option<u32>,
accept_http1: bool,
service_builder: ServiceBuilder<L>,
Expand All @@ -117,6 +118,7 @@ impl Default for Server<Identity> {
http2_keepalive_timeout: None,
http2_adaptive_window: None,
http2_max_pending_accept_reset_streams: None,
http2_max_header_list_size: None,
max_frame_size: None,
accept_http1: false,
service_builder: Default::default(),
Expand Down Expand Up @@ -313,6 +315,17 @@ impl<L> Server<L> {
}
}

/// Sets the max size of received header frames.
///
/// This will default to whatever the default in hyper is. As of v1.4.1, it is 16 KiB.
#[must_use]
pub fn http2_max_header_list_size(self, max: impl Into<Option<u32>>) -> Self {
Server {
http2_max_header_list_size: max.into(),
..self
}
}

/// Sets the maximum frame size to use for HTTP2.
///
/// Passing `None` will do nothing.
Expand Down Expand Up @@ -482,6 +495,7 @@ impl<L> Server<L> {
http2_keepalive_timeout: self.http2_keepalive_timeout,
http2_adaptive_window: self.http2_adaptive_window,
http2_max_pending_accept_reset_streams: self.http2_max_pending_accept_reset_streams,
http2_max_header_list_size: self.http2_max_header_list_size,
max_frame_size: self.max_frame_size,
accept_http1: self.accept_http1,
}
Expand Down Expand Up @@ -514,6 +528,7 @@ impl<L> Server<L> {
let init_stream_window_size = self.init_stream_window_size;
let max_concurrent_streams = self.max_concurrent_streams;
let timeout = self.timeout;
let max_header_list_size = self.http2_max_header_list_size;
let max_frame_size = self.max_frame_size;
let http2_only = !self.accept_http1;

Expand Down Expand Up @@ -558,6 +573,10 @@ impl<L> Server<L> {
.max_pending_accept_reset_streams(http2_max_pending_accept_reset_streams)
.max_frame_size(max_frame_size);

if let Some(max_header_list_size) = max_header_list_size {
builder.http2().max_header_list_size(max_header_list_size);
}

builder
};

Expand Down