-
-
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
Improve interoperability with http #2060
Conversation
This PR should fix the following issues:
Related pull requests: |
Thank you for putting this together! I do want to improve the type interoperability with |
Would you like to try to rebase this on to the 0.12-dev branch? I'm hope to prep a release this week. :) |
601a507
to
0699394
Compare
@seanmonstar: Updated. I found that of the conversions and trait implementations I initially proposed, only the conversion from As for the part for treating Please have a look. |
I made a few changes to make reqwest types compatible with
http
types. This will enable a lot of interesting uses (such as a reverse proxy, example code attached in the end).By interoperability with http I mean the following four components:
TryFrom
fromhttp::Request<http::Body>
toreqwest::Request
(already implemented prior to this PR)TryFrom
fromreqwest::Response
tohttp::Response<reqwest::Body>
http::Body
forreqwest::Body
tower::Service<reqwest::Request, Response=reqwest::Response, Error=reqwest::Error>
forreqwest::Client
(also already implemented prior to this PR)In fact, all the implementation logic is already there. I only assembled these together.
Now with all these trait implementations and conversion functions, it becomes easy to play with axum and other
http
-based frameworks. Here's an example reverse proxy written in axum:I noticed that the wrapper
ImplStream
is not really used anywhere, so I removed it. In my opinion, it is sensible to interpret areqwest::Body
as aStream
or ahttp::Body
on its own. Please let me know if there are considerations where it's still necessary.