From 82f1877d4b6cba2fac432670ec306160aee5c501 Mon Sep 17 00:00:00 2001 From: Eric Kidd Date: Thu, 26 Jan 2017 12:05:44 -0500 Subject: [PATCH] Implement `Body::sized` This is necessary for APIs such as BigML's, where we may need to send extremely large request bodies, but chunked transfer encoding is not supported. This is a partial fix for seanmonstar/reqwest#49. --- src/body.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/body.rs b/src/body.rs index 77a09e430..a1bff3ea4 100644 --- a/src/body.rs +++ b/src/body.rs @@ -27,11 +27,17 @@ impl Body { } } - /* - pub fn sized(reader: (), len: u64) -> Body { - unimplemented!() + /// Create a `Body` from a `Reader` where we can predict the size in + /// advance, but where we don't want to load the data in memory. This + /// is useful if we need to ensure `Content-Length` is passed with the + /// request. + pub fn sized(reader: R, len: u64) -> Body { + Body { + reader: Kind::Reader(Box::new(reader), Some(len)), + } } + /* pub fn chunked(reader: ()) -> Body { unimplemented!() }