Skip to content

Commit

Permalink
feat(server): add Connection::http2_max_header_list_size option (#2828
Browse files Browse the repository at this point in the history
)

This allows setting the HTTP/2 `SETTINGS_MAX_HEADER_LIST_SIZE` which advertises to the peer the maximum header size allowed, and internally is enforced.

Closes #2826
  • Loading branch information
silence-coding authored May 18, 2022
1 parent 67b7313 commit a32658c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/proto/h2/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024; // 1mb
const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024; // 1mb
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb
// 16 MB "sane default" taken from golang http2
const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: u32 = 16 << 20;

#[derive(Clone, Debug)]
pub(crate) struct Config {
Expand All @@ -49,6 +51,7 @@ pub(crate) struct Config {
#[cfg(feature = "runtime")]
pub(crate) keep_alive_timeout: Duration,
pub(crate) max_send_buffer_size: usize,
pub(crate) max_header_list_size: u32,
}

impl Default for Config {
Expand All @@ -65,6 +68,7 @@ impl Default for Config {
#[cfg(feature = "runtime")]
keep_alive_timeout: Duration::from_secs(20),
max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE,
max_header_list_size: DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE,
}
}
}
Expand Down Expand Up @@ -116,6 +120,7 @@ where
.initial_window_size(config.initial_stream_window_size)
.initial_connection_window_size(config.initial_conn_window_size)
.max_frame_size(config.max_frame_size)
.max_header_list_size(config.max_header_list_size)
.max_send_buffer_size(config.max_send_buffer_size);
if let Some(max) = config.max_concurrent_streams {
builder.max_concurrent_streams(max);
Expand Down
10 changes: 10 additions & 0 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,16 @@ impl<E> Http<E> {
self
}

/// Sets the max size of received header frames.
///
/// Default is currently ~16MB, but may change.
#[cfg(feature = "http2")]
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
pub fn http2_max_header_list_size(&mut self, max: u32) -> &mut Self {
self.h2_builder.max_header_list_size = max;
self
}

/// Set the maximum buffer size for the connection.
///
/// Default is ~400kb.
Expand Down

0 comments on commit a32658c

Please sign in to comment.