Skip to content

Commit 82f1877

Browse files
committed
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 #49.
1 parent 1768981 commit 82f1877

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/body.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,17 @@ impl Body {
2727
}
2828
}
2929

30-
/*
31-
pub fn sized(reader: (), len: u64) -> Body {
32-
unimplemented!()
30+
/// Create a `Body` from a `Reader` where we can predict the size in
31+
/// advance, but where we don't want to load the data in memory. This
32+
/// is useful if we need to ensure `Content-Length` is passed with the
33+
/// request.
34+
pub fn sized<R: Read + Send + 'static>(reader: R, len: u64) -> Body {
35+
Body {
36+
reader: Kind::Reader(Box::new(reader), Some(len)),
37+
}
3338
}
3439

40+
/*
3541
pub fn chunked(reader: ()) -> Body {
3642
unimplemented!()
3743
}

0 commit comments

Comments
 (0)