Skip to content
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

Create a http::Response<hyper::Body> from a reqwest::Response #1954

Closed
wants to merge 1 commit into from

Conversation

Threated
Copy link
Contributor

As discussed in #1951 here is the conversion trait implementation.

impl From<Response> for http::Response<hyper::Body> {
fn from(r: Response) -> http::Response<hyper::Body> {
let (parts, body) = r.res.into_parts();
http::Response::from_parts(parts, hyper::Body::wrap_stream(body))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we could give the body without wrapping it prematurely, and then anyone needing to unify it could wrap it themselves. If they didn't need to, we could save them a boxed trait object.

Is there any reason we shouldn't do that?

Copy link
Contributor Author

@Threated Threated Aug 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good I just don't know how as the body returned by into_parts has the private Decoder type so we need to wrap it some way right? If this were a method I suppose we could return http::Response<impl Stream<..>>. What do you think?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In at least the blocking implementation, I'd like to use a similar conversion trait for a simple Vec<u8>. See how ureq provides a few of them:

https://github.com/algesten/ureq/blob/916ffbffbe098d28d9ac142054484fd71423d9a6/src/http_interop.rs#L55-L129

Seems there's also #1258, #1483, #1612 to track and implement (something) like this. The latter being a PR implementing the same trait in src/async_impl/response.rs but for anything with a From<Decoder>. @seanmonstar is one of these PRs "superseding" the other? Can I help gain some traction on any of these?

@Threated
Copy link
Contributor Author

cc @seanmonstar Can you address my question?

@shouya
Copy link
Contributor

shouya commented Dec 13, 2023

I realized this PR exists after I posted #2060, which solves the same issue but with a slightly larger scope. I personally think it's better to make reqwest types http compatible, e.g. make reqwest::Body a valid http_body::Body, than exposing the underlying hyper types.

@Threated
Copy link
Contributor Author

Threated commented Dec 13, 2023

Yeah that is true especially with hyper 1.0 - getting rid of its own body type now.
Closing this in favor of your PR.

@Threated Threated closed this Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants