-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http_interop: Implement
Request
conversion for http::request::Parts
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)
- Loading branch information
Showing
2 changed files
with
75 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Replace `impl From<http::request::Builder> for Request` with `TryFrom` because the conversion is fallible | ||
(implement in terms of `From<http::request::Parts>`: `builder.body(())?.into_parts().0.into()`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters