Add StreamBody (#237)

This adds `StreamBody` which converts a `Stream` of `Bytes` into a `http_body::Body`.

---

As suggested by Kestrer on Discord it would make sense for axum to provide different kinds of body types other than `Empty`, `Full`, and `hyper::Body`. There is also some talk about [splitting up `hyper::Body`](https://github.com/hyperium/hyper/issues/2345) so this can be seen as getting started on that effort. axum's body types could be moved to hyper or http-body if thats the direction we decide on.

The types I'm thinking about adding are:

- `StreamBody`-  added in this PR
- `AsyncReadBody` - similar to [http-body#41](https://github.com/hyperium/http-body/pull/41/files)
- `ChannelBody` - similar to `hyper::Body::channel`
This commit is contained in:
David Pedersen
2021-08-22 14:41:51 +02:00
committed by GitHub
parent 5ae94b6a24
commit 2322d39800
5 changed files with 110 additions and 0 deletions
+1
View File
@@ -198,6 +198,7 @@ macro_rules! impl_into_response_for_body {
impl_into_response_for_body!(hyper::Body);
impl_into_response_for_body!(Full<Bytes>);
impl_into_response_for_body!(Empty<Bytes>);
impl_into_response_for_body!(crate::body::StreamBody);
impl<E> IntoResponse for http_body::combinators::BoxBody<Bytes, E>
where