Skip to content

Commit 810435f

Browse files
committed
feat(server): add http1_writev config option for servers
Closes #1527
1 parent 7eca445 commit 810435f

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

src/proto/h1/io.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ where
6666
}
6767

6868
pub fn set_flush_pipeline(&mut self, enabled: bool) {
69+
debug_assert!(!self.write_buf.has_remaining());
6970
self.flush_pipeline = enabled;
70-
self.write_buf.set_strategy(if enabled {
71-
Strategy::Flatten
72-
} else {
73-
Strategy::Auto
74-
});
71+
if enabled {
72+
self.set_write_strategy_flatten();
73+
}
7574
}
7675

7776
pub fn set_max_buf_size(&mut self, max: usize) {

src/server/conn.rs

+19
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use error::{Kind, Parse};
3737
#[derive(Clone, Debug)]
3838
pub struct Http {
3939
exec: Exec,
40+
h1_writev: bool,
4041
mode: ConnectionMode,
4142
keep_alive: bool,
4243
max_buf_size: Option<usize>,
@@ -138,6 +139,7 @@ impl Http {
138139
pub fn new() -> Http {
139140
Http {
140141
exec: Exec::Default,
142+
h1_writev: true,
141143
mode: ConnectionMode::Fallback,
142144
keep_alive: true,
143145
max_buf_size: None,
@@ -157,6 +159,20 @@ impl Http {
157159
self
158160
}
159161

162+
/// Set whether HTTP/1 connections should try to use vectored writes,
163+
/// or always flatten into a single buffer.
164+
///
165+
/// Note that setting this to false may mean more copies of body data,
166+
/// but may also improve performance when an IO transport doesn't
167+
/// support vectored writes well, such as most TLS implementations.
168+
///
169+
/// Default is `true`.
170+
#[inline]
171+
pub fn http1_writev(&mut self, val: bool) -> &mut Self {
172+
self.h1_writev = val;
173+
self
174+
}
175+
160176
/// Sets whether HTTP2 is required.
161177
///
162178
/// Default is false
@@ -264,6 +280,9 @@ impl Http {
264280
if !self.keep_alive {
265281
conn.disable_keep_alive();
266282
}
283+
if !self.h1_writev {
284+
conn.set_write_strategy_flatten();
285+
}
267286
conn.set_flush_pipeline(self.pipeline_flush);
268287
if let Some(max) = self.max_buf_size {
269288
conn.set_max_buf_size(max);

src/server/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,21 @@ impl<I> Builder<I> {
175175
self
176176
}
177177

178+
/// Set whether HTTP/1 connections should try to use vectored writes,
179+
/// or always flatten into a single buffer.
180+
///
181+
/// # Note
182+
///
183+
/// Setting this to `false` may mean more copies of body data,
184+
/// but may also improve performance when an IO transport doesn't
185+
/// support vectored writes well, such as most TLS implementations.
186+
///
187+
/// Default is `true`.
188+
pub fn http1_writev(mut self, val: bool) -> Self {
189+
self.protocol.http1_writev(val);
190+
self
191+
}
192+
178193
/// Sets whether HTTP/2 is required.
179194
///
180195
/// Default is `false`.

0 commit comments

Comments
 (0)