diff --git a/.gitignore b/.gitignore index a9d37c56..b01913bd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ target Cargo.lock +.history \ No newline at end of file diff --git a/src/client/client.rs b/src/client/client.rs index cfdd267a..4ec3cd71 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -18,7 +18,10 @@ use super::pool::{ #[cfg(feature = "tcp")] use super::HttpConnector; use crate::body::{Body, HttpBody}; -use crate::common::{exec::BoxSendFuture, sync_wrapper::SyncWrapper, lazy as hyper_lazy, task, Future, Lazy, Pin, Poll}; +use crate::common::{ + exec::BoxSendFuture, lazy as hyper_lazy, sync_wrapper::SyncWrapper, task, Future, Lazy, Pin, + Poll, +}; use crate::rt::Executor; /// A Client to make outgoing HTTP requests. @@ -586,7 +589,7 @@ impl ResponseFuture { F: Future>> + Send + 'static, { Self { - inner: SyncWrapper::new(Box::pin(value)) + inner: SyncWrapper::new(Box::pin(value)), } } @@ -1181,8 +1184,6 @@ impl Builder { /// Sets the maximum frame size to use for HTTP2. /// /// Passing `None` will do nothing. - /// - /// If not set, hyper will use a default. #[cfg(feature = "http2")] #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] pub fn http2_max_frame_size(&mut self, sz: impl Into>) -> &mut Self { @@ -1278,6 +1279,46 @@ impl Builder { self } + /// Sets the maximum concurrent streams to use for HTTP2. + /// + /// Passing `None` will do nothing.. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_max_concurrent_streams(&mut self, max: u32) -> &mut Self { + self.conn_builder.http2_max_concurrent_streams(max); + self + } + + /// Sets the max header list size to use for HTTP2. + /// + /// Passing `None` will do nothing. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_max_header_list_size(&mut self, max: u32) -> &mut Self { + self.conn_builder.http2_max_header_list_size(max); + self + } + + /// Enables and disables the push feature for HTTP2. + /// + /// Passing `None` will do nothing. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_enable_push(&mut self, opt: bool) -> &mut Self { + self.conn_builder.http2_enable_push(opt); + self + } + + /// Sets the max header list size to use for HTTP2. + /// + /// Passing `None` will do nothing. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_header_table_size(&mut self, max: u32) -> &mut Self { + self.conn_builder.http2_header_table_size(max); + self + } + /// Set whether to retry requests that get disrupted before ever starting /// to write. /// diff --git a/src/client/conn.rs b/src/client/conn.rs index 85bc366b..b59bb5a1 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -812,14 +812,10 @@ impl Builder { /// Sets the maximum frame size to use for HTTP2. /// /// Passing `None` will do nothing. - /// - /// If not set, hyper will use a default. #[cfg(feature = "http2")] #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] pub fn http2_max_frame_size(&mut self, sz: impl Into>) -> &mut Self { - if let Some(sz) = sz.into() { - self.h2_builder.max_frame_size = sz; - } + self.h2_builder.max_frame_size = sz.into(); self } @@ -912,6 +908,46 @@ impl Builder { self } + /// Sets the maximum concurrent streams to use for HTTP2. + /// + /// Passing `None` will do nothing. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_max_concurrent_streams(&mut self, sz: impl Into>) -> &mut Self { + self.h2_builder.max_concurrent_streams = sz.into(); + self + } + + /// Sets the max header list size to use for HTTP2. + /// + /// Passing `None` will do nothing. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_max_header_list_size(&mut self, sz: impl Into>) -> &mut Self { + self.h2_builder.max_header_list_size = sz.into(); + self + } + + /// Enables and disables the push feature for HTTP2. + /// + /// Passing `None` will do nothing. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_enable_push(&mut self, sz: impl Into>) -> &mut Self { + self.h2_builder.enable_push = sz.into(); + self + } + + /// Sets the header table size to use for HTTP2. + /// + /// Passing `None` will do nothing. + #[cfg(feature = "http2")] + #[cfg_attr(docsrs, doc(cfg(feature = "http2")))] + pub fn http2_header_table_size(&mut self, sz: impl Into>) -> &mut Self { + self.h2_builder.header_table_size = sz.into(); + self + } + /// Constructs a connection with the configured options and IO. /// See [`client::conn`](crate::client::conn) for more. /// diff --git a/src/proto/h2/client.rs b/src/proto/h2/client.rs index 013f6fb5..69223210 100644 --- a/src/proto/h2/client.rs +++ b/src/proto/h2/client.rs @@ -44,7 +44,7 @@ pub(crate) struct Config { pub(crate) adaptive_window: bool, pub(crate) initial_conn_window_size: u32, pub(crate) initial_stream_window_size: u32, - pub(crate) max_frame_size: u32, + pub(crate) max_frame_size: Option, #[cfg(feature = "runtime")] pub(crate) keep_alive_interval: Option, #[cfg(feature = "runtime")] @@ -53,6 +53,10 @@ pub(crate) struct Config { pub(crate) keep_alive_while_idle: bool, pub(crate) max_concurrent_reset_streams: Option, pub(crate) max_send_buffer_size: usize, + pub(crate) max_concurrent_streams: Option, + pub(crate) max_header_list_size: Option, + pub(crate) enable_push: Option, + pub(crate) header_table_size: Option, } impl Default for Config { @@ -61,7 +65,7 @@ impl Default for Config { adaptive_window: false, initial_conn_window_size: DEFAULT_CONN_WINDOW, initial_stream_window_size: DEFAULT_STREAM_WINDOW, - max_frame_size: DEFAULT_MAX_FRAME_SIZE, + max_frame_size: Some(DEFAULT_MAX_FRAME_SIZE), #[cfg(feature = "runtime")] keep_alive_interval: None, #[cfg(feature = "runtime")] @@ -70,6 +74,10 @@ impl Default for Config { keep_alive_while_idle: false, max_concurrent_reset_streams: None, max_send_buffer_size: DEFAULT_MAX_SEND_BUF_SIZE, + max_concurrent_streams: None, + max_header_list_size: None, + enable_push: None, + header_table_size: None, } } } @@ -79,12 +87,26 @@ fn new_builder(config: &Config) -> Builder { builder .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_send_buffer_size(config.max_send_buffer_size) - .enable_push(false); + .max_send_buffer_size(config.max_send_buffer_size); if let Some(max) = config.max_concurrent_reset_streams { builder.max_concurrent_reset_streams(max); } + if let Some(max) = config.max_concurrent_streams { + builder.max_concurrent_streams(max); + } + if let Some(max) = config.max_header_list_size { + builder.max_header_list_size(max); + } + if let Some(opt) = config.enable_push { + builder.enable_push(opt); + } + if let Some(max) = config.max_frame_size { + builder.max_frame_size(max); + } + if let Some(max) = config.header_table_size { + builder.header_table_size(max); + } + builder }