1
0
Fork 0
mirror of https://github.com/tokio-rs/axum.git synced 2025-04-26 13:56:22 +02:00

remove Limited from public API

This commit is contained in:
David Pedersen 2023-03-24 15:19:17 +01:00
parent 1fd6dbb4e6
commit f1c0b118ea

View file

@ -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<Limited<Body>>, 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<Request, Request>;
/// 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<Limited<Body>, 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<Body, Body>;
}
impl RequestExt for Request {
@ -318,7 +323,7 @@ impl RequestExt for Request {
})
}
fn with_limited_body(self) -> Result<Request<Limited<Body>>, Request> {
fn with_limited_body(self) -> Result<Request, Request> {
// 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::<DefaultBodyLimitKind>().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<Limited<Body>, Body> {
fn into_limited_body(self) -> Result<Body, Body> {
self.with_limited_body()
.map(Request::into_body)
.map_err(Request::into_body)