diff --git a/src/client/conn.rs b/src/client/conn.rs index ae9d90434d..ee767104aa 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -75,6 +75,7 @@ pub struct Builder { h1_writev: bool, h1_title_case_headers: bool, h1_read_buf_exact_size: Option, + h1_max_buf_size: Option, http2: bool, } @@ -435,6 +436,7 @@ impl Builder { h1_writev: true, h1_read_buf_exact_size: None, h1_title_case_headers: false, + h1_max_buf_size: None, http2: false, } } @@ -460,8 +462,21 @@ impl Builder { pub(super) fn h1_read_buf_exact_size(&mut self, sz: Option) -> &mut Builder { self.h1_read_buf_exact_size = sz; + self.h1_max_buf_size = None; self } + + pub(super) fn h1_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.h1_max_buf_size = Some(max); + self.h1_read_buf_exact_size = None; + self + } + /// Sets whether HTTP2 is required. /// /// Default is false. @@ -510,6 +525,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.h1_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) diff --git a/src/client/mod.rs b/src/client/mod.rs index 7ae870b84e..7cba82c466 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -901,6 +901,8 @@ impl Builder { /// Sets the exact size of the read buffer to *always* use. /// + /// Note that setting this option unsets the `http1_max_buf_size` option. + /// /// Default is an adaptive read buffer. #[inline] pub fn http1_read_buf_exact_size(&mut self, sz: usize) -> &mut Self { @@ -908,6 +910,21 @@ impl Builder { self } + /// Set the maximum buffer size for the connection. + /// + /// Default is ~400kb. + /// + /// Note that setting this option unsets the `http1_read_exact_buf_size` option. + /// + /// # Panics + /// + /// The minimum value allowed is 8192. This method panics if the passed `max` is less than the minimum. + #[inline] + pub fn http1_max_buf_size(&mut self, max: usize) -> &mut Self { + self.conn_builder.h1_max_buf_size(max); + self + } + /// Set whether HTTP/1 connections will write header names as title case at /// the socket level. ///