feat(transport): Expose http/2 settings (#28)

* expose http2 settings

* add client http2 options
This commit is contained in:
John Doneth
2019-10-04 10:08:37 -04:00
committed by Lucio Franco
parent afa9d9d236
commit 0218d58c28
3 changed files with 67 additions and 1 deletions
+23
View File
@@ -24,6 +24,8 @@ pub struct Endpoint {
pub(super) buffer_size: Option<usize>, pub(super) buffer_size: Option<usize>,
pub(super) interceptor_headers: pub(super) interceptor_headers:
Option<Arc<dyn Fn(&mut http::HeaderMap) + Send + Sync + 'static>>, Option<Arc<dyn Fn(&mut http::HeaderMap) + Send + Sync + 'static>>,
pub(super) init_stream_window_size: Option<u32>,
pub(super) init_connection_window_size: Option<u32>,
} }
impl Endpoint { impl Endpoint {
@@ -101,6 +103,25 @@ impl Endpoint {
self 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 initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.init_stream_window_size = sz.into();
self
}
/// Sets the max connection-level flow control for HTTP2
///
/// Default is 65,535
pub fn initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.init_connection_window_size = sz.into();
self
}
/// Enable TLS and apply the CA as the root certificate. /// Enable TLS and apply the CA as the root certificate.
/// ///
/// Providing an optional domain to override. If `None` is passed to this /// Providing an optional domain to override. If `None` is passed to this
@@ -185,6 +206,8 @@ impl From<Uri> for Endpoint {
tls: None, tls: None,
buffer_size: None, buffer_size: None,
interceptor_headers: None, interceptor_headers: None,
init_stream_window_size: None,
init_connection_window_size: None,
} }
} }
} }
+39
View File
@@ -47,6 +47,9 @@ pub struct Server {
// timeout: Option<Duration>, // timeout: Option<Duration>,
#[cfg(feature = "tls")] #[cfg(feature = "tls")]
tls: Option<TlsAcceptor>, tls: Option<TlsAcceptor>,
init_stream_window_size: Option<u32>,
init_connection_window_size: Option<u32>,
max_concurrent_streams: Option<u32>,
} }
impl Server { impl Server {
@@ -123,6 +126,36 @@ impl Server {
// self // 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 initial_stream_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.init_stream_window_size = sz.into();
self
}
/// Sets the max connection-level flow control for HTTP2
///
/// Default is 65,535
pub fn initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
self.init_connection_window_size = sz.into();
self
}
/// Sets the [`SETTINGS_MAX_CONCURRENT_STREAMS`][spec] option for HTTP2
/// connections.
///
/// Default is no limit (`None`).
///
/// [spec]: https://http2.github.io/http2-spec/#SETTINGS_MAX_CONCURRENT_STREAMS
pub fn max_concurrent_streams(&mut self, max: impl Into<Option<u32>>) -> &mut Self {
self.max_concurrent_streams = max.into();
self
}
/// Intercept the execution of gRPC methods. /// Intercept the execution of gRPC methods.
/// ///
/// ``` /// ```
@@ -162,6 +195,9 @@ impl Server {
{ {
let interceptor = self.interceptor.clone(); let interceptor = self.interceptor.clone();
let concurrency_limit = self.concurrency_limit; let concurrency_limit = self.concurrency_limit;
let init_connection_window_size = self.init_connection_window_size;
let init_stream_window_size = self.init_stream_window_size;
let max_concurrent_streams = self.max_concurrent_streams;
// let timeout = self.timeout.clone(); // let timeout = self.timeout.clone();
let incoming = hyper::server::accept::from_stream(async_stream::try_stream! { let incoming = hyper::server::accept::from_stream(async_stream::try_stream! {
@@ -190,6 +226,9 @@ impl Server {
hyper::Server::builder(incoming) hyper::Server::builder(incoming)
.http2_only(true) .http2_only(true)
.http2_initial_connection_window_size(init_connection_window_size)
.http2_initial_stream_window_size(init_stream_window_size)
.http2_max_concurrent_streams(max_concurrent_streams)
.serve(svc) .serve(svc)
.await .await
.map_err(map_err)?; .map_err(map_err)?;
+5 -1
View File
@@ -34,7 +34,11 @@ impl Connection {
#[cfg(not(feature = "tls"))] #[cfg(not(feature = "tls"))]
let connector = connector(); let connector = connector();
let settings = Builder::new().http2_only(true).clone(); let settings = Builder::new()
.http2_initial_stream_window_size(endpoint.init_stream_window_size)
.http2_initial_connection_window_size(endpoint.init_connection_window_size)
.http2_only(true)
.clone();
let stack = ServiceBuilder::new() let stack = ServiceBuilder::new()
.layer_fn(|s| AddOrigin::new(s, endpoint.uri.clone())) .layer_fn(|s| AddOrigin::new(s, endpoint.uri.clone()))