feat: parsing body reqeusts to String and Vec<u8> seems to be working
@@ -147,3 +147,42 @@ impl<T: 'static + Send + serde::Serialize> IntoResponse for Json<T> {
.unwrap()
}
}
+
+impl <S: 'static> Extract<S> for String {
+ type Fut = FutureObj<'static, Result<Self, Response>>;
+
+ fn extract(
+ data: &mut S,
+ req: &mut Request,
+ params: &RouteMatch<'_>,
+ ) -> Self::Fut {
+ let mut body = std::mem::replace(req.body_mut(), Body::empty());
+
+ FutureObj::new(Box::new(async move {
+ fn mk_err<T>(_: T) -> Response { StatusCode::BAD_REQUEST.into_response() }
+ let body = await!(body.to_vec().map_err(mk_err))?;
+ let string = String::from_utf8(body).map_err(mk_err)?;
+ Ok(string)
+ }))
+ }
+}
+
+impl <S: 'static> Extract<S> for Vec<u8> {
+ type Fut = FutureObj<'static, Result<Self, Response>>;
+
+ fn extract(
+ data: &mut S,
+ req: &mut Request,
+ params: &RouteMatch<'_>,
+ ) -> Self::Fut {
+ let mut body = std::mem::replace(req.body_mut(), Body::empty());
+
+ FutureObj::new(Box::new(async move {
+ fn mk_err<T>(_: T) -> Response { StatusCode::BAD_REQUEST.into_response() }
+ let body = await!(body.to_vec().map_err(mk_err))?;
+ Ok(body)
+ }))
+ }
+}
+
+
