Struct axum::extract::DefaultBodyLimit
source · [−]#[non_exhaustive]pub struct DefaultBodyLimit;
Expand description
Layer for configuring the default request body limit.
For security reasons, Bytes
will, by default, not accept bodies larger than 2MB. This also
applies to extractors that uses Bytes
internally such as String
, Json
, and Form
.
This middleware provides ways to configure that.
Note that if an extractor consumes the body directly with Body::data
, or similar, the
default limit is not applied.
Implementations
sourceimpl DefaultBodyLimit
impl DefaultBodyLimit
sourcepub fn disable() -> DefaultBodyLimit
pub fn disable() -> DefaultBodyLimit
Disable the default request body limit.
This must be used to receive bodies larger than the default limit of 2MB using Bytes
or
an extractor built on it such as String
, Json
, Form
.
Note that if you’re accepting data from untrusted remotes it is recommend to add your own
limit such as tower_http::limit
.
Example
use axum::{
Router,
routing::get,
body::{Bytes, Body},
extract::DefaultBodyLimit,
};
use tower_http::limit::RequestBodyLimitLayer;
use http_body::Limited;
let app: Router<_, Limited<Body>> = Router::new()
.route("/", get(|body: Bytes| async {}))
// Disable the default limit
.layer(DefaultBodyLimit::disable())
// Set a different limit
.layer(RequestBodyLimitLayer::new(10 * 1000 * 1000));
Trait Implementations
sourceimpl Clone for DefaultBodyLimit
impl Clone for DefaultBodyLimit
sourcefn clone(&self) -> DefaultBodyLimit
fn clone(&self) -> DefaultBodyLimit
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for DefaultBodyLimit
impl Debug for DefaultBodyLimit
sourceimpl<S> Layer<S> for DefaultBodyLimit
impl<S> Layer<S> for DefaultBodyLimit
Auto Trait Implementations
impl RefUnwindSafe for DefaultBodyLimit
impl Send for DefaultBodyLimit
impl Sync for DefaultBodyLimit
impl Unpin for DefaultBodyLimit
impl UnwindSafe for DefaultBodyLimit
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
impl<V, T> VZip<V> for Twhere
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more