We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
StreamedBody
1 parent 9c0d2ef commit a49c9dcCopy full SHA for a49c9dc
1 file changed
src/http/body.rs
@@ -107,6 +107,27 @@ impl<T: AsRef<[u8]>> Body for BoundedBody<T> {
107
}
108
109
110
+/// An HTTP body with an unknown length
111
+#[derive(Debug)]
112
+pub struct StreamedBody<S: AsyncRead>(S);
113
+
114
+impl<S: AsyncRead> StreamedBody<S> {
115
+ /// Wrap an `AsyncRead` impl in a type that provides a [`Body`] implementation.
116
+ pub fn new(s: S) -> Self {
117
+ Self(s)
118
+ }
119
+}
120
+impl<S: AsyncRead> AsyncRead for StreamedBody<S> {
121
+ async fn read(&mut self, buf: &mut [u8]) -> crate::io::Result<usize> {
122
+ self.0.read(buf).await
123
124
125
+impl<S: AsyncRead> Body for StreamedBody<S> {
126
+ fn len(&self) -> Option<usize> {
127
+ None
128
129
130
131
impl Body for Empty {
132
fn len(&self) -> Option<usize> {
133
Some(0)
0 commit comments