feat(server): add http1_writev config option for servers

Closes #1527
This commit is contained in:
Sean McArthur
2018-06-04 10:59:07 -07:00
parent 7eca445ff9
commit 810435f146
3 changed files with 38 additions and 5 deletions

View File

@@ -66,12 +66,11 @@ where
} }
pub fn set_flush_pipeline(&mut self, enabled: bool) { pub fn set_flush_pipeline(&mut self, enabled: bool) {
debug_assert!(!self.write_buf.has_remaining());
self.flush_pipeline = enabled; self.flush_pipeline = enabled;
self.write_buf.set_strategy(if enabled { if enabled {
Strategy::Flatten self.set_write_strategy_flatten();
} else { }
Strategy::Auto
});
} }
pub fn set_max_buf_size(&mut self, max: usize) { pub fn set_max_buf_size(&mut self, max: usize) {

View File

@@ -37,6 +37,7 @@ use error::{Kind, Parse};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Http { pub struct Http {
exec: Exec, exec: Exec,
h1_writev: bool,
mode: ConnectionMode, mode: ConnectionMode,
keep_alive: bool, keep_alive: bool,
max_buf_size: Option<usize>, max_buf_size: Option<usize>,
@@ -138,6 +139,7 @@ impl Http {
pub fn new() -> Http { pub fn new() -> Http {
Http { Http {
exec: Exec::Default, exec: Exec::Default,
h1_writev: true,
mode: ConnectionMode::Fallback, mode: ConnectionMode::Fallback,
keep_alive: true, keep_alive: true,
max_buf_size: None, max_buf_size: None,
@@ -157,6 +159,20 @@ impl Http {
self self
} }
/// Set whether HTTP/1 connections should try to use vectored writes,
/// or always flatten into a single buffer.
///
/// Note that setting this to false may mean more copies of body data,
/// but may also improve performance when an IO transport doesn't
/// support vectored writes well, such as most TLS implementations.
///
/// Default is `true`.
#[inline]
pub fn http1_writev(&mut self, val: bool) -> &mut Self {
self.h1_writev = val;
self
}
/// Sets whether HTTP2 is required. /// Sets whether HTTP2 is required.
/// ///
/// Default is false /// Default is false
@@ -264,6 +280,9 @@ impl Http {
if !self.keep_alive { if !self.keep_alive {
conn.disable_keep_alive(); conn.disable_keep_alive();
} }
if !self.h1_writev {
conn.set_write_strategy_flatten();
}
conn.set_flush_pipeline(self.pipeline_flush); conn.set_flush_pipeline(self.pipeline_flush);
if let Some(max) = self.max_buf_size { if let Some(max) = self.max_buf_size {
conn.set_max_buf_size(max); conn.set_max_buf_size(max);

View File

@@ -175,6 +175,21 @@ impl<I> Builder<I> {
self self
} }
/// Set whether HTTP/1 connections should try to use vectored writes,
/// or always flatten into a single buffer.
///
/// # Note
///
/// Setting this to `false` may mean more copies of body data,
/// but may also improve performance when an IO transport doesn't
/// support vectored writes well, such as most TLS implementations.
///
/// Default is `true`.
pub fn http1_writev(mut self, val: bool) -> Self {
self.protocol.http1_writev(val);
self
}
/// Sets whether HTTP/2 is required. /// Sets whether HTTP/2 is required.
/// ///
/// Default is `false`. /// Default is `false`.