-
Notifications
You must be signed in to change notification settings - Fork 177
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
http_interop: Implement Request
conversion for http::request::Parts
#669
http_interop: Implement Request
conversion for http::request::Parts
#669
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, poor decision on my part to not implement as a TryFrom
originally (and missing that Parts
was a thing).
@kade-robertson great! By the way, apologies for the commit/PR message. I always write them very business-y and to the point to get the point across and justify the change, but realize now that it may not come across nicely on the original author. Let's wait for @algesten to confirm whether we can make such a breaking change now or in the future. We can anyway:
But then I'm not exactly sure how much value there is in providing a |
49a3063
to
e0c532d
Compare
No worries! It's a very valid point -- not sure why I didn't do it that way originally.
You're totally right! When I implemented this before I even left a message in the PR that I wasn't really sure what the purpose would be. I admittedly had some bias towards the
I took a look and this branch looks good (if it's desired) to me, though I guess what the exact plan to update this isn't decided on yet. Maybe there's some way to take advantage of the fact that this was already a non-default feature? Have the "fixed" implementations exposed under a second feature and deprecate the first one until a |
Tackling the doc-issues in #670 🙂 |
Yeah that one seems to work fine though I have some doubts/suspicions about the UTF-8 "fallibility" part...
This (adding a non-conflicting new trait implementation and |
e0c532d
to
df125ac
Compare
H! @MarijnS95 welcome to ureq! Instead of commenting on the sub-issues, I'll do it here. Thank you so much for taking the time to look at this. I think all of this makes perfect sense, and I agree we should have this instead of the current variant of http interop. However, I would like to avoid a breaking change. What do you think about deprecating the old http-interop and placing this under a new feature flag? |
@algesten glad to be here! We've been using It's only one implementation that doesn't really seem to be useful (IMO), the new trait conversions can all be added without adding breaking changes. I don't think we need a new feature for this, and renaming |
8b3f2e8
to
32dde58
Compare
As it turns out a (Not sure why though... it could be caught in type-specific scenarios, just not in |
I'm probably being stupid, but apart from the fact that turning |
@algesten a |
@MarijnS95 sure, I get that. I think like this: 1) What could make Builder go wrong? 2) Is it likely to go wrong? 3) Is there another code path available if you need to detect this error? (Like completing the My goal here is to avoid a breaking change, but still have an answer for what to do. I agree |
@algesten sure thing.
In the end all we can do is extend the current doc-comment to explain the situation. If the user has a let request = builder.body(())?; // Check the error
let (parts, ()) = request.into_parts();
let request: ureq::Request = parts.into(); // Use the new conversion added in this PR |
@MarijnS95 This sounds good. At the moment we continue to live with the suboptimal situation of Would you mind adding the code you show above into the rust doc? |
a2aa5e0
to
30caf52
Compare
@algesten yeah that was the intent. I've replaced the current documentation entirely as And added a quick |
I found the current conversion for `http::request::Builder` to be rather useless when the `http` crate and various crates providing `http` interfaces like `oauth2` are designed to provide an `http::Request` directly, and there being no way to convert from a `http::Request` back into its `http::request::Builder`. That, together with strange infallible defaults instead of providing `TryFrom` make the current implementation cumbersome to use. Fortunately `http` provides `http::Request::into_parts()` to get back a `Parts` structure (which is wrapped in `Result<>` inside `http::request::Builder` as sole member!) together with the request body (a generic type) which the user can manually pass to `send_string()`, `send_bytes()` or `call()` if there's no data. Implement a `From<http::request::Parts> for ureq::Request` to support this case, making `ureq` finally capable of sending `http::Request`s. (Note that, despite exclusively consisting of `Result<Parts>`, `http::request::Builder` has no constructor from `Ok(Parts {..})` which would have also facilitated this use-case somewhat)
30caf52
to
9ac2764
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Let's merge it!
@algesten are there any release plans for a semver-compatible minor/patch release with these changes? I'd like to start cleaning up some user crates with the new conversion methods 🎉 |
@MarijnS95 yes! I'm waiting for #679 but maybe that can wait. 🤔 |
Cool! Not too much hurry in hindsight, it seems the crates I'm willing to apply this to also have other outstanding problems that make this harder to achieve. |
Fixes #656
Closes #501
Closes #520
I found the current conversion for
http::request::Builder
to be rather useless when thehttp
crate and various crates providinghttp
interfaces likeoauth2
are designed to provide anhttp::Request
directly, and there being no way to convert from ahttp::Request
back into itshttp::request::Builder
. That, together with strange infallible defaults instead of providingTryFrom
make the current implementation cumbersome to use.Fortunately
http
provideshttp::Request::into_parts()
to get back aParts
structure (which is wrapped inResult<>
insidehttp::request::Builder
as sole member!) together with the request body (a generic type) which the user can manually pass tosend_string()
,send_bytes()
orcall()
if there's no data.Implement a
From<http::request::Parts> for ureq::Request
to support this case, makingureq
finally capable of sendinghttp::Request
s.(Note that, despite exclusively consisting of
Result<Parts>
,http::request::Builder
has no constructor fromOk(Parts {..})
which would have also facilitated this use-case somewhat)TODO
Some more ideas and things I found while working on this crate:
doc_cfg
when building for docs.rs: Enable all features in documentation and utilizedoc_auto_cfg
#670;From<http::request::Builder>
withTryFrom<>
(breaking change!).Builder
altogether, see below!