mirror of
https://github.com/tokio-rs/axum.git
synced 2026-09-08 00:00:24 +02:00
remove Limited from public API
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
use crate::body::Body;
|
use crate::body::Body;
|
||||||
use crate::extract::{DefaultBodyLimitKind, FromRequest, FromRequestParts, Request};
|
use crate::extract::{DefaultBodyLimitKind, FromRequest, FromRequestParts, Request};
|
||||||
use futures_util::future::BoxFuture;
|
use futures_util::future::BoxFuture;
|
||||||
use http_body_util::Limited;
|
|
||||||
|
|
||||||
mod sealed {
|
mod sealed {
|
||||||
pub trait Sealed {}
|
pub trait Sealed {}
|
||||||
@@ -257,12 +256,18 @@ pub trait RequestExt: sealed::Sealed + Sized {
|
|||||||
/// Apply the [default body limit](crate::extract::DefaultBodyLimit).
|
/// Apply the [default body limit](crate::extract::DefaultBodyLimit).
|
||||||
///
|
///
|
||||||
/// If it is disabled, return the request as-is in `Err`.
|
/// 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](crate::extract::DefaultBodyLimit) is in place, or not wrapped if the
|
||||||
/// default limit is disabled.
|
/// 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 {
|
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
|
// update docs in `axum-core/src/extract/default_body_limit.rs` and
|
||||||
// `axum/src/docs/extract.md` if this changes
|
// `axum/src/docs/extract.md` if this changes
|
||||||
const DEFAULT_LIMIT: usize = 2_097_152; // 2 mb
|
const DEFAULT_LIMIT: usize = 2_097_152; // 2 mb
|
||||||
@@ -326,13 +331,13 @@ impl RequestExt for Request {
|
|||||||
match self.extensions().get::<DefaultBodyLimitKind>().copied() {
|
match self.extensions().get::<DefaultBodyLimitKind>().copied() {
|
||||||
Some(DefaultBodyLimitKind::Disable) => Err(self),
|
Some(DefaultBodyLimitKind::Disable) => Err(self),
|
||||||
Some(DefaultBodyLimitKind::Limit(limit)) => {
|
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()
|
self.with_limited_body()
|
||||||
.map(Request::into_body)
|
.map(Request::into_body)
|
||||||
.map_err(Request::into_body)
|
.map_err(Request::into_body)
|
||||||
|
|||||||
Reference in New Issue
Block a user