diff --git a/src/client/connect/http.rs b/src/client/connect/http.rs index 0ffe1ca403..d30f7ff19e 100644 --- a/src/client/connect/http.rs +++ b/src/client/connect/http.rs @@ -35,6 +35,8 @@ pub struct HttpConnector { nodelay: bool, resolver: R, reuse_address: bool, + send_buf_size: Option, + recv_buf_size: Option, } /// Extra information about the transport when an HttpConnector is used. @@ -124,6 +126,8 @@ impl HttpConnector { nodelay: false, resolver, reuse_address: false, + send_buf_size: None, + recv_buf_size: None, } } @@ -161,6 +165,18 @@ impl HttpConnector { self.nodelay = nodelay; } + /// Sets the value of the SO_SNDBUF option on the socket. + #[inline] + pub fn set_send_buf_size(&mut self, size: Option) { + self.send_buf_size = size; + } + + /// Sets the value of the SO_RCVBUF option on the socket. + #[inline] + pub fn set_recv_buf_size(&mut self, size: Option) { + self.recv_buf_size = size; + } + /// Set that all sockets are bound to the configured address before connection. /// /// If `None`, the sockets will not be bound. @@ -248,6 +264,8 @@ where nodelay: self.nodelay, port, reuse_address: self.reuse_address, + send_buf_size: self.send_buf_size, + recv_buf_size: self.recv_buf_size, } } } @@ -269,6 +287,8 @@ fn invalid_url(err: InvalidUrl, handle: &Option) -> HttpConn port: 0, happy_eyeballs_timeout: None, reuse_address: false, + send_buf_size: None, + recv_buf_size: None, } } @@ -304,6 +324,8 @@ pub struct HttpConnecting { nodelay: bool, port: u16, reuse_address: bool, + send_buf_size: Option, + recv_buf_size: Option, } enum State { @@ -353,6 +375,14 @@ impl Future for HttpConnecting { sock.set_keepalive(Some(dur))?; } + if let Some(size) = self.send_buf_size { + sock.set_send_buffer_size(size)?; + } + + if let Some(size) = self.recv_buf_size { + sock.set_recv_buffer_size(size)?; + } + sock.set_nodelay(self.nodelay)?; let extra = HttpInfo {