-
Notifications
You must be signed in to change notification settings - Fork 195
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 Wrapper Type RFC & Implementation #2912
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.
This looks great so far!
/// | ||
/// Depending on the internal storage type, this operation may be free or it may have an internal | ||
/// cost. | ||
pub fn into_http0x(self) -> http::Request<B> { |
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.
Hypothetically, if there was ever a http 0.3 release before 1.0, this would need an additional method that would break the naming convention, right?
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.
yeah, we should either make this a From impl or name it more precisely
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.
Should it be fallible in case it's not possible to convert in the future (due to losing information or something)?
} | ||
|
||
/// Returns the body associated with the request | ||
pub fn body(&self) -> &B { |
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.
Would need body_mut
too.
Also, it would be super nice to have a conveniences like map_body
/take_body
since we frequently have to juggle mem::swap
s in the orchestrator code to accomplish that.
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.
yeah there are a bunch of methods that need to be added to support everything
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 so far! I originally had a question whether
impl TryFrom<http0::HeaderValue> for HeaderValue
is considered exposing a 3rd party type in public API, but this should be ok as it's done in a way that is not ossified, as called out in the RFC.
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
f4755f4
to
aa1bbc1
Compare
A new generated diff is ready to view.
A new doc preview is ready to view. |
|
||
#[derive(Debug)] | ||
/// An HTTP Request Type | ||
pub struct Request<B = SdkBody> { |
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.
Have you tried using the Request/Response with Surf? Does it play nicely with that API?
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.
the API works fine except for extensions. We'd need to maintain a copy of each extension map we aim to target or the maps would need to support construction from TypeId directly
|
||
/// A Request URI | ||
#[derive(Debug, Clone)] | ||
pub struct Uri { |
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.
Would love to have nice URI manipulations on this in the future 😄
} | ||
|
||
/// Adds an extension to the request extensions | ||
pub fn add_extension<T: Send + Sync + Clone + 'static>(&mut self, extension: T) { |
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.
Should this be fallible in case the underlying HTTP library doesn't support extensions?
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.
so currently we have fallibility in the conversion to the final request type—you actually don't know what the final request type is going to be until the request is dispatched.
We can probably refactor at some point to remove the need to set request extensions and instead handle it during the conversion to http03x::Request
...not a bad idea actually, hmmm
key: impl AsHeaderName, | ||
value: impl AsHeaderName, |
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.
key: impl AsHeaderName, | |
value: impl AsHeaderName, | |
key: impl AsHeaderComponent, | |
value: impl AsHeaderComponent, |
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
Co-authored-by: John DiSanti <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
Co-authored-by: John DiSanti <[email protected]>
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
let http0 = req.into_http03x().unwrap(); | ||
assert_eq!(http0.uri(), "http://bar.com"); | ||
} | ||
|
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.
Just note somewhere that there are more tests to add. For example, the Uri::set_endpoint
method.
A new generated diff is ready to view.
A new doc preview is ready to view. |
A new generated diff is ready to view.
A new doc preview is ready to view. |
Motivation and Context
Implementation of the HTTP request wrapper type from RFC
Description
RFC + implementation of HttpRequest
Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.