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
This commit is contained in:
		| @@ -35,6 +35,8 @@ const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024; // 1mb | |||||||
| const DEFAULT_STREAM_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_FRAME_SIZE: u32 = 1024 * 16; // 16kb | ||||||
| const DEFAULT_MAX_SEND_BUF_SIZE: usize = 1024 * 400; // 400kb | 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)] | #[derive(Clone, Debug)] | ||||||
| pub(crate) struct Config { | pub(crate) struct Config { | ||||||
| @@ -49,6 +51,7 @@ pub(crate) struct Config { | |||||||
|     #[cfg(feature = "runtime")] |     #[cfg(feature = "runtime")] | ||||||
|     pub(crate) keep_alive_timeout: Duration, |     pub(crate) keep_alive_timeout: Duration, | ||||||
|     pub(crate) max_send_buffer_size: usize, |     pub(crate) max_send_buffer_size: usize, | ||||||
|  |     pub(crate) max_header_list_size: u32, | ||||||
| } | } | ||||||
|  |  | ||||||
| impl Default for Config { | impl Default for Config { | ||||||
| @@ -65,6 +68,7 @@ impl Default for Config { | |||||||
|             #[cfg(feature = "runtime")] |             #[cfg(feature = "runtime")] | ||||||
|             keep_alive_timeout: Duration::from_secs(20), |             keep_alive_timeout: Duration::from_secs(20), | ||||||
|             max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE, |             max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE, | ||||||
|  |             max_header_list_size: DEFAULT_SETTINGS_MAX_HEADER_LIST_SIZE, | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| @@ -116,6 +120,7 @@ where | |||||||
|             .initial_window_size(config.initial_stream_window_size) |             .initial_window_size(config.initial_stream_window_size) | ||||||
|             .initial_connection_window_size(config.initial_conn_window_size) |             .initial_connection_window_size(config.initial_conn_window_size) | ||||||
|             .max_frame_size(config.max_frame_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); |             .max_send_buffer_size(config.max_send_buffer_size); | ||||||
|         if let Some(max) = config.max_concurrent_streams { |         if let Some(max) = config.max_concurrent_streams { | ||||||
|             builder.max_concurrent_streams(max); |             builder.max_concurrent_streams(max); | ||||||
|   | |||||||
| @@ -519,6 +519,16 @@ impl<E> Http<E> { | |||||||
|         self |         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. |     /// Set the maximum buffer size for the connection. | ||||||
|     /// |     /// | ||||||
|     /// Default is ~400kb. |     /// Default is ~400kb. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user