diff --git a/src/client/multipart.rs b/src/client/multipart.rs index eb94aa1f..a9b20b75 100644 --- a/src/client/multipart.rs +++ b/src/client/multipart.rs @@ -139,11 +139,23 @@ impl Form { } /// Consume this instance and transform into an instance of Body for use in a request. - pub(crate) fn stream(mut self) -> Body { + pub(crate) fn stream(self) -> Body { if self.inner.fields.is_empty() { return Body::empty(); } + Body::stream(self.into_stream()) + } + + /// Produce a stream of the bytes in this `Form`, consuming it. + pub fn into_stream(mut self) -> impl Stream> + Send + Sync { + if self.inner.fields.is_empty() { + let empty_stream: Pin< + Box> + Send + Sync>, + > = Box::pin(futures_util::stream::empty()); + return empty_stream; + } + // create initial part to init reduce chain let (name, part) = self.inner.fields.remove(0); let start = Box::pin(self.part_stream(name, part)) @@ -160,7 +172,7 @@ impl Form { let last = stream::once(future::ready(Ok( format!("--{}--\r\n", self.boundary()).into() ))); - Body::stream(stream.chain(last)) + Box::pin(stream.chain(last)) } /// Generate a hyper2::Body stream for a single Part instance of a Form request.