-
Notifications
You must be signed in to change notification settings - Fork 260
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 the builtin Request/Response types #1939
Conversation
Signed-off-by: Ryan Levick <[email protected]>
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 to me!
I left a couple of comments inline, but I agree that this is the right approach to take.
sdk/rust/src/http.rs
Outdated
/// Technically headers do not have to be utf8 encoded but this type assumes they are. | ||
/// If you know you'll be dealing with non-utf8 encoded headers, reach more a more powerful | ||
/// response type like that found in the `http` crate. | ||
pub fn headers(&self) -> &[(String, String)] { |
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.
could we maybe instead introduce a headers_raw
(and headers_raw_mut
) that returns (String, Vec<u8>)
?
I'm imagining that we'd internally store headers as something like (String, HeaderVal)
, where HeaderVal
is something like
enum HeaderVal {
Bytes(Vec<u8>),
String(String),
Both(Vec<u8>, String),
}
I bet there's some more optimal representation of this for the case where Bytes
contains valid unicode, too.
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 am somewhat worried about this. I think I've managed to push a change that supports this without being a maintenance burden, be we do have to get comfortable at some point saying that these types will never cover 100% of use cases and a 3rd party crate might be necessary.
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.
A couple of suggestions, all of which could be handled in follow-up.
Signed-off-by: Ryan Levick <[email protected]>
011576c
to
b363229
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; thanks!
0d182a6
to
90e8c8f
Compare
Signed-off-by: Ryan Levick <[email protected]>
90e8c8f
to
aa06684
Compare
Signed-off-by: Ryan Levick <[email protected]>
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.
A slight nit and one comment of some substance—but almost there!
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.
🚢🚢🚢
Signed-off-by: Ryan Levick <[email protected]>
ecdce33
to
b337273
Compare
@@ -99,6 +384,23 @@ impl std::fmt::Display for Method { | |||
} | |||
|
|||
impl IncomingRequest { | |||
/// The incoming request Uri | |||
pub fn uri(&self) -> String { |
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.
Can the user get this as a Url object or would they need to parse the string?
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.
They would need to parse. The thought by behind it is to not make the http
crate part of the public API for these types.
This is meant as an alternative to #1931. It improves the
Request
/Response
types with an API that is useable, flexible, and powerful and hopefully enough to cover 80% of use cases. For more advanced use cases, we would recommend using a third party crate likehttp
.Note: The one slightly awkward API choice is that
RequestBuilder::uri
is infallible so that even if the user passes a garbage URI it still "works" - they'll likely only see any error when the try to use the uri. I think this is the right balance of easy of use without sacrificing too much protection against misuse.