feat(http2): allow configuring the HTTP/2 frame size
The default of 16K is taken from h2.
This commit is contained in:
committed by
Sean McArthur
parent
042c770603
commit
b64464562a
@@ -525,6 +525,18 @@ impl Builder {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the maximum frame size to use for HTTP2.
|
||||||
|
///
|
||||||
|
/// Passing `None` will do nothing.
|
||||||
|
///
|
||||||
|
/// If not set, hyper will use a default.
|
||||||
|
pub fn http2_max_frame_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||||
|
if let Some(sz) = sz.into() {
|
||||||
|
self.h2_builder.max_frame_size = sz;
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets an interval for HTTP2 Ping frames should be sent to keep a
|
/// Sets an interval for HTTP2 Ping frames should be sent to keep a
|
||||||
/// connection alive.
|
/// connection alive.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -30,12 +30,14 @@ type ConnEof = oneshot::Receiver<Never>;
|
|||||||
// for performance.
|
// for performance.
|
||||||
const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024 * 5; // 5mb
|
const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024 * 5; // 5mb
|
||||||
const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024 * 2; // 2mb
|
const DEFAULT_STREAM_WINDOW: u32 = 1024 * 1024 * 2; // 2mb
|
||||||
|
const DEFAULT_MAX_FRAME_SIZE: u32 = 1024 * 16; // 16kb
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct Config {
|
pub(crate) struct Config {
|
||||||
pub(crate) adaptive_window: bool,
|
pub(crate) adaptive_window: bool,
|
||||||
pub(crate) initial_conn_window_size: u32,
|
pub(crate) initial_conn_window_size: u32,
|
||||||
pub(crate) initial_stream_window_size: u32,
|
pub(crate) initial_stream_window_size: u32,
|
||||||
|
pub(crate) max_frame_size: u32,
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
pub(crate) keep_alive_interval: Option<Duration>,
|
pub(crate) keep_alive_interval: Option<Duration>,
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
@@ -50,6 +52,7 @@ impl Default for Config {
|
|||||||
adaptive_window: false,
|
adaptive_window: false,
|
||||||
initial_conn_window_size: DEFAULT_CONN_WINDOW,
|
initial_conn_window_size: DEFAULT_CONN_WINDOW,
|
||||||
initial_stream_window_size: DEFAULT_STREAM_WINDOW,
|
initial_stream_window_size: DEFAULT_STREAM_WINDOW,
|
||||||
|
max_frame_size: DEFAULT_MAX_FRAME_SIZE,
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
keep_alive_interval: None,
|
keep_alive_interval: None,
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
@@ -74,6 +77,7 @@ where
|
|||||||
let (h2_tx, mut conn) = Builder::default()
|
let (h2_tx, mut conn) = Builder::default()
|
||||||
.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)
|
||||||
.enable_push(false)
|
.enable_push(false)
|
||||||
.handshake::<_, SendBuf<B::Data>>(io)
|
.handshake::<_, SendBuf<B::Data>>(io)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -26,12 +26,14 @@ use crate::{Body, Response};
|
|||||||
// so is more likely to use more resources than a client would.
|
// so is more likely to use more resources than a client would.
|
||||||
const DEFAULT_CONN_WINDOW: u32 = 1024 * 1024; // 1mb
|
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
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub(crate) struct Config {
|
pub(crate) struct Config {
|
||||||
pub(crate) adaptive_window: bool,
|
pub(crate) adaptive_window: bool,
|
||||||
pub(crate) initial_conn_window_size: u32,
|
pub(crate) initial_conn_window_size: u32,
|
||||||
pub(crate) initial_stream_window_size: u32,
|
pub(crate) initial_stream_window_size: u32,
|
||||||
|
pub(crate) max_frame_size: u32,
|
||||||
pub(crate) max_concurrent_streams: Option<u32>,
|
pub(crate) max_concurrent_streams: Option<u32>,
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
pub(crate) keep_alive_interval: Option<Duration>,
|
pub(crate) keep_alive_interval: Option<Duration>,
|
||||||
@@ -45,6 +47,7 @@ impl Default for Config {
|
|||||||
adaptive_window: false,
|
adaptive_window: false,
|
||||||
initial_conn_window_size: DEFAULT_CONN_WINDOW,
|
initial_conn_window_size: DEFAULT_CONN_WINDOW,
|
||||||
initial_stream_window_size: DEFAULT_STREAM_WINDOW,
|
initial_stream_window_size: DEFAULT_STREAM_WINDOW,
|
||||||
|
max_frame_size: DEFAULT_MAX_FRAME_SIZE,
|
||||||
max_concurrent_streams: None,
|
max_concurrent_streams: None,
|
||||||
#[cfg(feature = "runtime")]
|
#[cfg(feature = "runtime")]
|
||||||
keep_alive_interval: None,
|
keep_alive_interval: None,
|
||||||
@@ -98,7 +101,8 @@ where
|
|||||||
let mut builder = h2::server::Builder::default();
|
let mut builder = h2::server::Builder::default();
|
||||||
builder
|
builder
|
||||||
.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);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -309,6 +309,18 @@ impl<E> Http<E> {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Sets the maximum frame size to use for HTTP2.
|
||||||
|
///
|
||||||
|
/// Passing `None` will do nothing.
|
||||||
|
///
|
||||||
|
/// If not set, hyper will use a default.
|
||||||
|
pub fn http2_max_frame_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||||
|
if let Some(sz) = sz.into() {
|
||||||
|
self.h2_builder.max_frame_size = sz;
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
|
/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
|
||||||
/// connections.
|
/// connections.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user