From 7dece69cc61d2728b63b1c6b18168750f07a1738 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Fri, 24 Mar 2023 15:36:36 +0100 Subject: [PATCH] handle additional error wrapping --- axum-core/src/extract/rejection.rs | 7 +++++++ axum-extra/src/extract/multipart.rs | 2 +- axum/src/extract/multipart.rs | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/axum-core/src/extract/rejection.rs b/axum-core/src/extract/rejection.rs index e656fe71..7c52a449 100644 --- a/axum-core/src/extract/rejection.rs +++ b/axum-core/src/extract/rejection.rs @@ -16,10 +16,17 @@ impl FailedToBufferBody { where E: Into, { + // two layers of boxes where because `with_limited_body` + // wraps the `http_body_util::Limited` in a `axum_core::Body` + // which also wraps the error type let box_error = match err.into().downcast::() { Ok(err) => err.into_inner(), Err(err) => err, }; + let box_error = match box_error.downcast::() { + Ok(err) => err.into_inner(), + Err(err) => err, + }; match box_error.downcast::() { Ok(err) => Self::LengthLimitError(LengthLimitError::from_err(err)), Err(err) => Self::UnknownBodyError(UnknownBodyError::from_err(err)), diff --git a/axum-extra/src/extract/multipart.rs b/axum-extra/src/extract/multipart.rs index bf47be25..fbe63f5e 100644 --- a/axum-extra/src/extract/multipart.rs +++ b/axum-extra/src/extract/multipart.rs @@ -100,7 +100,7 @@ where async fn from_request(req: Request, _state: &S) -> Result { let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?; let stream = match req.with_limited_body() { - Ok(limited) => Body::new(limited), + Ok(limited) => limited.into_body(), Err(unlimited) => unlimited.into_body(), }; let multipart = multer::Multipart::new(stream, boundary); diff --git a/axum/src/extract/multipart.rs b/axum/src/extract/multipart.rs index 7f6332d1..ed4312dd 100644 --- a/axum/src/extract/multipart.rs +++ b/axum/src/extract/multipart.rs @@ -64,7 +64,7 @@ where async fn from_request(req: Request, _state: &S) -> Result { let boundary = parse_boundary(req.headers()).ok_or(InvalidBoundary)?; let stream = match req.with_limited_body() { - Ok(limited) => Body::new(limited), + Ok(limited) => limited.into_body(), Err(unlimited) => unlimited.into_body(), }; let multipart = multer::Multipart::new(stream, boundary);