refactor: Upload extractor, 429 refusal test, stricter contract test

This commit is contained in:
2026-10-25 21:59:31 +01:00
parent c8d9138349
commit 2ac1d4e0cf
10 changed files with 139 additions and 52 deletions

View File

@@ -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);