refactor: Upload extractor, 429 refusal test, stricter contract test
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
|
||||
use axum::{
|
||||
extract::{
|
||||
FromRequest, FromRequestParts, Path, Query, Request,
|
||||
FromRequest, FromRequestParts, Multipart, Path, Query, Request,
|
||||
multipart::MultipartRejection,
|
||||
rejection::{JsonRejection, PathRejection, QueryRejection},
|
||||
},
|
||||
http::{StatusCode, request::Parts},
|
||||
@@ -52,6 +53,29 @@ impl From<PathRejection> for MalformedRequest {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MultipartRejection> for MalformedRequest {
|
||||
fn from(r: MultipartRejection) -> Self {
|
||||
Self {
|
||||
status: r.status(),
|
||||
message: r.body_text(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `axum::extract::Multipart` with refusals in the one error shape.
|
||||
pub struct Upload(pub Multipart);
|
||||
|
||||
impl<S> FromRequest<S> for Upload
|
||||
where
|
||||
S: Send + Sync,
|
||||
{
|
||||
type Rejection = MalformedRequest;
|
||||
|
||||
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
|
||||
Ok(Self(Multipart::from_request(req, state).await?))
|
||||
}
|
||||
}
|
||||
|
||||
/// `axum::Json` with refusals in the one error shape.
|
||||
pub struct Body<T>(pub T);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user