Add bytes() function to blocking::Response
This commit is contained in:
committed by
Sean McArthur
parent
f267e1435d
commit
526afe9d86
@@ -5,6 +5,7 @@ use std::net::SocketAddr;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
use bytes::Bytes;
|
||||||
use http;
|
use http;
|
||||||
use hyper::header::HeaderMap;
|
use hyper::header::HeaderMap;
|
||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
@@ -225,6 +226,25 @@ impl Response {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the full response body as `Bytes`.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// # fn run() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
/// let bytes = reqwest::blocking::get("http://httpbin.org/ip")?.bytes()?;
|
||||||
|
///
|
||||||
|
/// println!("bytes: {:?}", bytes);
|
||||||
|
/// # Ok(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
pub fn bytes(self) -> crate::Result<Bytes> {
|
||||||
|
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.
|
/// Get the response text.
|
||||||
///
|
///
|
||||||
/// This method decodes the response body with BOM sniffing
|
/// This method decodes the response body with BOM sniffing
|
||||||
|
|||||||
Reference in New Issue
Block a user