Add RequestExt and RequestPartsExt - #1301
Conversation
| let mut req = Request::new(()); | ||
| *req.version_mut() = self.version(); | ||
| *req.method_mut() = self.method().clone(); | ||
| *req.uri_mut() = self.uri().clone(); | ||
| *req.headers_mut() = std::mem::take(self.headers_mut()); | ||
| *req.extensions_mut() = std::mem::take(self.extensions_mut()); | ||
| let (mut parts, _) = req.into_parts(); |
There was a problem hiding this comment.
Hm, this is kinda unfortunate. As an alternative, we could require B: Default and use mem::take, wdyt about that? Pretty much everything in http-body including the boxed body types seems to implement Default if the inner buffer does, the only exception being Limited but I'm sure there it can be added too.
There was a problem hiding this comment.
Yeah thats probably fine. I'll change it.
There was a problem hiding this comment.
Hm actually its kinda weird having to write this on your extractor. Feels kinda arbitrary from the user perspective 🤔
@@ -180,7 +171,7 @@ mod tests {
impl<S, B> FromRequest<S, B> for WorksForCustomExtractor
where
S: Send + Sync,
- B: Send + 'static,
+ B: Send + Default + 'static,
String: FromRef<S> + FromRequest<(), B>,
{
type Rejection = <String as FromRequest<(), B>>::Rejection;There was a problem hiding this comment.
Right, I didn't consider that you'd want to use this from functions generic over B. Maybe http can be updated to provide .parts(&self) -> &Parts and .parts_mut(&mut self) -> &mut Parts on Request and Response, the current implementation of the types would trivially allow this.
There was a problem hiding this comment.
I remember there was some discussion around that a while ago hyperium/http#511.
Fixes #1297