Skip to main content

SizeLimit

Struct SizeLimit 

Source
pub struct SizeLimit { /* private fields */ }
Expand description

Represents size limit of the stream to prevent DoS attacks.

Please refer Constraints for more info.

Implementations§

Source§

impl SizeLimit

Source

pub fn new() -> Self

Creates the default size limits.

The whole stream and each field are unbounded, while the preamble is limited to 32 KiB, each field’s header block to 64 KiB, and each boundary’s transport padding to 8 KiB.

Source

pub const fn whole_stream(self, limit: u64) -> Self

Sets size limit for the whole stream.

A finite limit includes the MIME epilogue after the closing boundary. Completing iteration therefore waits for the source to reach EOF, and source errors in the epilogue are propagated. With the default unbounded limit (u64::MAX), parsing stops at the closing boundary.

Source

pub const fn preamble(self, limit: u64) -> Self

Sets the size limit for data before the first multipart boundary.

The default is 32 KiB. Multipart form submissions normally have no preamble, but MIME permits one before the first boundary.

Source

pub const fn per_field(self, limit: u64) -> Self

Sets size limit for each field.

Source

pub const fn headers(self, limit: u64) -> Self

Sets size limit for a field’s full header block.

Source

pub const fn boundary_padding(self, limit: u64) -> Self

Sets the maximum number of spaces and tabs after each boundary.

The default is 8 KiB. This applies independently of field and stream limits, to opening, intermediate, and closing boundaries. The boundary marker and terminating CRLF are not included in this limit.

Source

pub fn for_field<N: Into<String>>(self, field_name: N, limit: u64) -> Self

Sets size limit for a specific field, it overrides the per_field value for this field.

It is useful when you want to set a size limit on a textual field which will be stored in memory to avoid potential DoS attacks from attackers running the server out of memory.

Trait Implementations§

Source§

impl Debug for SizeLimit

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SizeLimit

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Forget for SizeLimit

§

impl Freeze for SizeLimit
where *const u8 is !null: Freeze, PhantomData<(String, u64)>: Freeze,

§

impl Move for SizeLimit

§

impl RefUnwindSafe for SizeLimit

§

impl Send for SizeLimit
where RawTable<(String, u64)>: Send,

§

impl Sync for SizeLimit
where RawTable<(String, u64)>: Sync,

§

impl Unpin for SizeLimit
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for SizeLimit

§

impl UnwindSafe for SizeLimit

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.