Skip to content

Commit

Permalink
feat(client): add conn::Builder::max_buf_size()
Browse files Browse the repository at this point in the history
This allows users to configure a limit to client connections' read and
write buffers.

Closes hyperium#1748
  • Loading branch information
almielczarek committed Jan 20, 2019
1 parent c69d109 commit 4b3e600
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/client/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct Builder {
h1_writev: bool,
h1_title_case_headers: bool,
h1_read_buf_exact_size: Option<usize>,
max_buf_size: Option<usize>,
http2: bool,
}

Expand Down Expand Up @@ -435,6 +436,7 @@ impl Builder {
h1_writev: true,
h1_read_buf_exact_size: None,
h1_title_case_headers: false,
max_buf_size: None,
http2: false,
}
}
Expand Down Expand Up @@ -462,6 +464,24 @@ impl Builder {
self.h1_read_buf_exact_size = sz;
self
}

/// Set the maximum buffer size for the connection.
///
/// Default is ~400kb.
///
/// # Panics
///
/// The minimum value allowed is 8192. This method panics if the passed `max` is less than the minimum.
pub fn max_buf_size(&mut self, max: usize) -> &mut Self {
assert!(
max >= proto::h1::MINIMUM_MAX_BUFFER_SIZE,
"the max_buf_size cannot be smaller than the minimum that h1 specifies."
);

self.max_buf_size = Some(max);
self
}

/// Sets whether HTTP2 is required.
///
/// Default is false.
Expand Down Expand Up @@ -510,6 +530,9 @@ where
if let Some(sz) = self.builder.h1_read_buf_exact_size {
conn.set_read_buf_exact_size(sz);
}
if let Some(max) = self.builder.max_buf_size {
conn.set_max_buf_size(max);
}
let cd = proto::h1::dispatch::Client::new(rx);
let dispatch = proto::h1::Dispatcher::new(cd, conn);
Either::A(dispatch)
Expand Down

0 comments on commit 4b3e600

Please sign in to comment.