diff --git a/src/blocking/response.rs b/src/blocking/response.rs index 4977539..7f08cc5 100644 --- a/src/blocking/response.rs +++ b/src/blocking/response.rs @@ -5,6 +5,7 @@ use std::net::SocketAddr; use std::pin::Pin; use std::time::Duration; +use bytes::Bytes; use http; use hyper::header::HeaderMap; #[cfg(feature = "json")] @@ -225,6 +226,25 @@ impl Response { }) } + /// Get the full response body as `Bytes`. + /// + /// # Example + /// + /// ``` + /// # fn run() -> Result<(), Box> { + /// let bytes = reqwest::blocking::get("http://httpbin.org/ip")?.bytes()?; + /// + /// println!("bytes: {:?}", bytes); + /// # Ok(()) + /// # } + /// ``` + pub fn bytes(self) -> crate::Result { + wait::timeout(self.inner.bytes(), self.timeout).map_err(|e| match e { + wait::Waited::TimedOut(e) => crate::error::decode(e), + wait::Waited::Inner(e) => e, + }) + } + /// Get the response text. /// /// This method decodes the response body with BOM sniffing