-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert response body to Stream #734
Comments
You can make a stream in a slightly round-about way with: async fn next_chunk(mut response: reqwest::Response) -> Option<(Result<bytes::Bytes, reqwest::Error>, reqwest::Response)> {
let chunk = response.chunk().await;
let chunk = chunk.transpose()?;
Some((chunk, response))
}
let body = futures_util::stream::unfold(response, next_chunk); But yes, it would be easier if it was just an |
Yeah, that's why I wrote that there is no "direct" way. Another way is to use async-stream which does not have this problems, but instead you occasionally get weird compiler errors (see e.g. here). |
Yeah, I switched from the |
@seanmonstar is this issue is something you would consider before releasing |
What if we added |
That'd be perfect! |
This converts the `Response` into a `Stream` of `Bytes`. Closes #734
This converts the `Response` into a `Stream` of `Bytes`. Closes #734
This converts the `Response` into a `Stream` of `Bytes`. Closes #734
Right now, there is no "direct" way to consume a response body as a
Stream<Item = Result<Bytes>>
. IMO this would be a good thing (either via someinto_stream
function, or a direct impl, like in 0.9). I went ahead and made the existinginto_stream
inBody
public, but this also requires to makeImplStream
public, which is probably suboptimal.Related: How about enabling the
stream
feature by default, just as it is done in hyper 0.13?The text was updated successfully, but these errors were encountered: