From f1c0b118ea8ad660aa147e710789d717585c08fc Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Fri, 24 Mar 2023 15:19:17 +0100 Subject: [PATCH] remove `Limited` from public API --- axum-core/src/ext_traits/request.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/axum-core/src/ext_traits/request.rs b/axum-core/src/ext_traits/request.rs index 0e69f261..36c34723 100644 --- a/axum-core/src/ext_traits/request.rs +++ b/axum-core/src/ext_traits/request.rs @@ -1,7 +1,6 @@ use crate::body::Body; use crate::extract::{DefaultBodyLimitKind, FromRequest, FromRequestParts, Request}; use futures_util::future::BoxFuture; -use http_body_util::Limited; mod sealed { pub trait Sealed {} @@ -257,12 +256,18 @@ pub trait RequestExt: sealed::Sealed + Sized { /// Apply the [default body limit](crate::extract::DefaultBodyLimit). /// /// If it is disabled, return the request as-is in `Err`. - fn with_limited_body(self) -> Result>, Request>; + /// + /// Note that while the `Ok` and `Err` types are the same, [`http_body_util::Limited`] will have + /// been applied in the `Ok` case. + fn with_limited_body(self) -> Result; - /// Consumes the request, returning the body wrapped in [`Limited`] if a + /// Consumes the request, returning the body wrapped in [`http_body_util::Limited`] if a /// [default limit](crate::extract::DefaultBodyLimit) is in place, or not wrapped if the /// default limit is disabled. - fn into_limited_body(self) -> Result, Body>; + /// + /// Note that while the `Ok` and `Err` types are the same, [`http_body_util::Limited`] will have + /// been applied in the `Ok` case. + fn into_limited_body(self) -> Result; } impl RequestExt for Request { @@ -318,7 +323,7 @@ impl RequestExt for Request { }) } - fn with_limited_body(self) -> Result>, Request> { + fn with_limited_body(self) -> Result { // update docs in `axum-core/src/extract/default_body_limit.rs` and // `axum/src/docs/extract.md` if this changes const DEFAULT_LIMIT: usize = 2_097_152; // 2 mb @@ -326,13 +331,13 @@ impl RequestExt for Request { match self.extensions().get::().copied() { Some(DefaultBodyLimitKind::Disable) => Err(self), Some(DefaultBodyLimitKind::Limit(limit)) => { - Ok(self.map(|b| http_body_util::Limited::new(b, limit))) + Ok(self.map(|b| Body::new(http_body_util::Limited::new(b, limit)))) } - None => Ok(self.map(|b| http_body_util::Limited::new(b, DEFAULT_LIMIT))), + None => Ok(self.map(|b| Body::new(http_body_util::Limited::new(b, DEFAULT_LIMIT)))), } } - fn into_limited_body(self) -> Result, Body> { + fn into_limited_body(self) -> Result { self.with_limited_body() .map(Request::into_body) .map_err(Request::into_body)