diff --git a/Cargo.toml b/Cargo.toml index 36b4ee00c..e50bf7a24 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,7 +58,7 @@ multipart = ["mime_guess"] trust-dns = ["trust-dns-resolver"] -stream = [] +stream = ["tokio/fs", "tokio-util"] socks = ["tokio-socks"] diff --git a/src/async_impl/body.rs b/src/async_impl/body.rs index d469c595e..afcce7177 100644 --- a/src/async_impl/body.rs +++ b/src/async_impl/body.rs @@ -7,7 +7,11 @@ use bytes::Bytes; use futures_core::Stream; use http_body::Body as HttpBody; use pin_project_lite::pin_project; +#[cfg(feature = "stream")] +use tokio::fs::File; use tokio::time::Sleep; +#[cfg(feature = "stream")] +use tokio_util::io::ReaderStream; /// An asynchronous request body. pub struct Body { @@ -208,6 +212,14 @@ impl From<&'static str> for Body { } } +#[cfg(feature = "stream")] +impl From for Body { + #[inline] + fn from(file: File) -> Body { + Body::wrap_stream(ReaderStream::new(file)) + } +} + impl fmt::Debug for Body { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("Body").finish()