Skip to content

Commit

Permalink
Body from tokio::fs::File
Browse files Browse the repository at this point in the history
  • Loading branch information
fredr committed Oct 18, 2021
1 parent fead177 commit d692c4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ blocking = ["futures-util/io", "tokio/rt-multi-thread", "tokio/sync"]

cookies = ["cookie_crate", "cookie_store", "time"]

gzip = ["async-compression", "async-compression/gzip", "tokio-util"]
gzip = ["async-compression", "async-compression/gzip"]

brotli = ["async-compression", "async-compression/brotli", "tokio-util"]
brotli = ["async-compression", "async-compression/brotli"]

deflate = ["async-compression", "async-compression/zlib", "tokio-util"]
deflate = ["async-compression", "async-compression/zlib"]

json = ["serde_json"]

Expand Down Expand Up @@ -100,7 +100,8 @@ lazy_static = "1.4"
log = "0.4"
mime = "0.3.16"
percent-encoding = "2.1"
tokio = { version = "1.0", default-features = false, features = ["net", "time"] }
tokio = { version = "1.0", default-features = false, features = ["net", "time", "fs"] }
tokio-util = { version = "0.6.0", default-features = false, features = ["codec", "io"] }
pin-project-lite = "0.2.0"
ipnet = "2.3"

Expand All @@ -125,7 +126,6 @@ time = { version = "0.2.11", optional = true }

## compression
async-compression = { version = "0.3.7", default-features = false, features = ["tokio"], optional = true }
tokio-util = { version = "0.6.0", default-features = false, features = ["codec", "io"], optional = true }

## socks
tokio-socks = { version = "0.5.1", optional = true }
Expand Down
9 changes: 9 additions & 0 deletions src/async_impl/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use bytes::Bytes;
use futures_core::Stream;
use http_body::Body as HttpBody;
use pin_project_lite::pin_project;
use tokio::fs::File;
use tokio::time::Sleep;
use tokio_util::io::ReaderStream;

/// An asynchronous request body.
pub struct Body {
Expand Down Expand Up @@ -208,6 +210,13 @@ impl From<&'static str> for Body {
}
}

impl From<File> for Body {
#[inline]
fn from(file: File) -> Body {
Body::stream(ReaderStream::new(file))
}
}

impl fmt::Debug for Body {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Body").finish()
Expand Down

0 comments on commit d692c4e

Please sign in to comment.