Add more SETTINGS frame options

This commit is contained in:
4JX
2022-08-17 17:23:30 +02:00
parent 53f15e5870
commit db6c602667
4 changed files with 114 additions and 14 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
target
Cargo.lock
.history

View File

@@ -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<Output = crate::Result<Response<Body>>> + 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<Option<u32>>) -> &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.
///

View File

@@ -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<Option<u32>>) -> &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<Option<u32>>) -> &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<Option<u32>>) -> &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<Option<bool>>) -> &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<Option<u32>>) -> &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.
///

View File

@@ -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<u32>,
#[cfg(feature = "runtime")]
pub(crate) keep_alive_interval: Option<Duration>,
#[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<usize>,
pub(crate) max_send_buffer_size: usize,
pub(crate) max_concurrent_streams: Option<u32>,
pub(crate) max_header_list_size: Option<u32>,
pub(crate) enable_push: Option<bool>,
pub(crate) header_table_size: Option<u32>,
}
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
}