Skip to content

Commit a32658c

Browse files
feat(server): add Connection::http2_max_header_list_size option (#2828)
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
1 parent 67b7313 commit a32658c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/proto/h2/server.rs

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024; // 1mb
3535
const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024; // 1mb
3636
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
3737
const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb
38+
// 16 MB "sane default" taken from golang http2
39+
const DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE: u32 = 16 << 20;
3840

3941
#[derive(Clone, Debug)]
4042
pub(crate) struct Config {
@@ -49,6 +51,7 @@ pub(crate) struct Config {
4951
#[cfg(feature = "runtime")]
5052
pub(crate) keep_alive_timeout: Duration,
5153
pub(crate) max_send_buffer_size: usize,
54+
pub(crate) max_header_list_size: u32,
5255
}
5356

5457
impl Default for Config {
@@ -65,6 +68,7 @@ impl Default for Config {
6568
#[cfg(feature = "runtime")]
6669
keep_alive_timeout: Duration::from_secs(20),
6770
max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE,
71+
max_header_list_size: DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE,
6872
}
6973
}
7074
}
@@ -116,6 +120,7 @@ where
116120
.initial_window_size(config.initial_stream_window_size)
117121
.initial_connection_window_size(config.initial_conn_window_size)
118122
.max_frame_size(config.max_frame_size)
123+
.max_header_list_size(config.max_header_list_size)
119124
.max_send_buffer_size(config.max_send_buffer_size);
120125
if let Some(max) = config.max_concurrent_streams {
121126
builder.max_concurrent_streams(max);

src/server/conn.rs

+10
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,16 @@ impl<E> Http<E> {
519519
self
520520
}
521521

522+
/// Sets the max size of received header frames.
523+
///
524+
/// Default is currently ~16MB, but may change.
525+
#[cfg(feature = "http2")]
526+
#[cfg_attr(docsrs, doc(cfg(feature = "http2")))]
527+
pub fn http2_max_header_list_size(&mut self, max: u32) -> &mut Self {
528+
self.h2_builder.max_header_list_size = max;
529+
self
530+
}
531+
522532
/// Set the maximum buffer size for the connection.
523533
///
524534
/// Default is ~400kb.

0 commit comments

Comments
 (0)