feat(http2): Add window size config options for Client and Server
Add `fn http2_initial_stream_window_size` and `fn http2_initial_connection_window_size` for client and server. Closes #1771
This commit is contained in:
committed by
Sean McArthur
parent
2114950cda
commit
7dcd4618c0
@@ -15,6 +15,7 @@ use std::sync::Arc;
|
||||
use bytes::Bytes;
|
||||
use futures::{Async, Future, Poll};
|
||||
use futures::future::{self, Either, Executor};
|
||||
use h2;
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use body::Payload;
|
||||
@@ -77,6 +78,7 @@ pub struct Builder {
|
||||
h1_read_buf_exact_size: Option<usize>,
|
||||
h1_max_buf_size: Option<usize>,
|
||||
http2: bool,
|
||||
h2_builder: h2::client::Builder,
|
||||
}
|
||||
|
||||
/// A future setting up HTTP over an IO object.
|
||||
@@ -431,6 +433,9 @@ impl Builder {
|
||||
/// Creates a new connection builder.
|
||||
#[inline]
|
||||
pub fn new() -> Builder {
|
||||
let mut h2_builder = h2::client::Builder::default();
|
||||
h2_builder.enable_push(false);
|
||||
|
||||
Builder {
|
||||
exec: Exec::Default,
|
||||
h1_writev: true,
|
||||
@@ -438,6 +443,7 @@ impl Builder {
|
||||
h1_title_case_headers: false,
|
||||
h1_max_buf_size: None,
|
||||
http2: false,
|
||||
h2_builder,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,6 +491,29 @@ impl Builder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
|
||||
/// stream-level flow control.
|
||||
///
|
||||
/// Default is 65,535
|
||||
///
|
||||
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
|
||||
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||
if let Some(sz) = sz.into() {
|
||||
self.h2_builder.initial_window_size(sz);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the max connection-level flow control for HTTP2
|
||||
///
|
||||
/// Default is 65,535
|
||||
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||
if let Some(sz) = sz.into() {
|
||||
self.h2_builder.initial_connection_window_size(sz);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Constructs a connection with the configured options and IO.
|
||||
#[inline]
|
||||
pub fn handshake<T, B>(&self, io: T) -> Handshake<T, B>
|
||||
@@ -532,7 +561,7 @@ where
|
||||
let dispatch = proto::h1::Dispatcher::new(cd, conn);
|
||||
Either::A(dispatch)
|
||||
} else {
|
||||
let h2 = proto::h2::Client::new(io, rx, self.builder.exec.clone());
|
||||
let h2 = proto::h2::Client::new(io, rx, &self.builder.h2_builder, self.builder.exec.clone());
|
||||
Either::B(h2)
|
||||
};
|
||||
|
||||
|
||||
@@ -971,6 +971,25 @@ impl Builder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
|
||||
/// stream-level flow control.
|
||||
///
|
||||
/// Default is 65,535
|
||||
///
|
||||
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
|
||||
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||
self.conn_builder.http2_initial_stream_window_size(sz.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the max connection-level flow control for HTTP2
|
||||
///
|
||||
/// Default is 65,535
|
||||
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||
self.conn_builder.http2_initial_connection_window_size(sz.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the maximum idle connection per host allowed in the pool.
|
||||
///
|
||||
/// Default is `usize::MAX` (no limit).
|
||||
|
||||
@@ -37,11 +37,8 @@ where
|
||||
T: AsyncRead + AsyncWrite + Send + 'static,
|
||||
B: Payload,
|
||||
{
|
||||
pub(crate) fn new(io: T, rx: ClientRx<B>, exec: Exec) -> Client<T, B> {
|
||||
let handshake = Builder::new()
|
||||
// we don't expose PUSH promises yet
|
||||
.enable_push(false)
|
||||
.handshake(io);
|
||||
pub(crate) fn new(io: T, rx: ClientRx<B>, builder: &Builder, exec: Exec) -> Client<T, B> {
|
||||
let handshake = builder.handshake(io);
|
||||
|
||||
Client {
|
||||
executor: exec,
|
||||
|
||||
@@ -239,6 +239,29 @@ impl<E> Http<E> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
|
||||
/// stream-level flow control.
|
||||
///
|
||||
/// Default is 65,535
|
||||
///
|
||||
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
|
||||
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||
if let Some(sz) = sz.into() {
|
||||
self.h2_builder.initial_window_size(sz);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the max connection-level flow control for HTTP2
|
||||
///
|
||||
/// Default is 65,535
|
||||
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||
if let Some(sz) = sz.into() {
|
||||
self.h2_builder.initial_connection_window_size(sz);
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
|
||||
/// connections.
|
||||
///
|
||||
|
||||
@@ -302,6 +302,25 @@ impl<I, E> Builder<I, E> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`SETTINGS_INITIAL_WINDOW_SIZE`][spec] option for HTTP2
|
||||
/// stream-level flow control.
|
||||
///
|
||||
/// Default is 65,535
|
||||
///
|
||||
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_INITIAL_WINDOW_SIZE
|
||||
pub fn http2_initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||
self.protocol.http2_initial_stream_window_size(sz.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the max connection-level flow control for HTTP2
|
||||
///
|
||||
/// Default is 65,535
|
||||
pub fn http2_initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
|
||||
self.protocol.http2_initial_connection_window_size(sz.into());
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
|
||||
/// connections.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user