-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat: add Sign trait #459
feat: add Sign trait #459
Conversation
1673ed4
to
89f835b
Compare
89f835b
to
01d7a16
Compare
Thanks a lot for your PR! However I'm thinking of a big refactor that build a |
hmm, it'd be a big refactor, but i have interest about this. let me have a try, but maybe it's better to make this refactor in a seperate pr. i'll change the newly added |
9bdd678
to
132700c
Compare
src/aws/v4.rs
Outdated
|
||
async fn sign( | ||
&self, | ||
req: &mut http::request::Request<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.
i found that it's not that easy to get the mut ref of the Parts
inside http::request::Request<T>
, to mut the req, it seems that it's still easier to pass &mut http::request::Request<T>
here if we'd like to pass a concerete Request
struct here.
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 found that it's not that easy to get the mut ref of the
Parts
insidehttp::request::Request<T>
, to mut the req
Would you like to elaborate further? It should be as straightforward as into_parts
and from_parts
. I want to avoid introduce an generice body in sign.
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.
we have to have the ownership of Request in the caller side, like this:
let (mut parts, body) = req.into_parts();
signer.sign(mut parts);
let req = Request::from_parts(parts, body);
if all you have is a &mut Request
, you can not easily get the parts
from it in the caller site.
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 proposed an RFC to http
: hyperium/http#712
we have to have the ownership of Request in the caller side, like this:
In read use cases, caller will always have the ownership of Request
. I still think it's better for us to just take Parts
in our API. So all imples and users don't need to play with Body
generic type.
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 RFC makes sense.
i've made the changes, PTAL
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.
if hyperium/http is not planned to exposes parts_mut()
(in hyperium/http#712 (comment)), i'm afraid that it might be better api to allow accepting a generic parameter in the Sign
trait.
in the current code base, there're a lot of call sites that only have got &mut Request
instead of an owned Request
. it's hard to get the mutable reference of Parts
.
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 strongly disagree with accepting a generic parameter. I prefer refactoring the entire codebase.
In opendal, we use reqsign in this way:
let req = balabala_build_request();
sign(&mut req);
client.send(req)
So it's totally fine for me to have:
let (head, body) = balabala_build_request().into_parts();
sign(&mut head);
client.send(Request::from_parts(head, body))
bdc1747
to
63ce993
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 to me. Thanks a lot for carrying this work!
background: apache/opendal#4960 (comment)
this PR introduced a Sign trait, which is suitable on the cases like when we want customize signing logics like apache/iceberg-rust#506