pub struct LengthLimit<T> { /* private fields */ }
Expand description

[AsyncRead] length limiter

Protects against a certain class of denial-of-service attacks wherein long chunked bodies are uploaded to web services.

The number of bytes will never be more than the provided byte limit. If the byte limit is exactly the length of the contained AsyncRead, it is considered an error.

Errors

This will return an error if the underlying AsyncRead does so or if the read length meets (or would exceed) the provided length limit. The returned std::io::Error will have an error kind of ErrorKind::InvalidData and a contained error of LengthLimitExceeded.

Implementations§

source§

impl<T> LengthLimit<T>

source

pub fn new(reader: T, max_bytes: usize) -> Self

Trait Implementations§

source§

impl<T: AsyncRead> AsyncRead for LengthLimit<T>

source§

fn poll_read( self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize>>

Attempt to read from the AsyncRead into buf. Read more
§

fn poll_read_vectored( self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
source§

impl<'__pin, T> Unpin for LengthLimit<T>where __Origin<'__pin, T>: Unpin,

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for LengthLimit<T>where T: RefUnwindSafe,

§

impl<T> Send for LengthLimit<T>where T: Send,

§

impl<T> Sync for LengthLimit<T>where T: Sync,

§

impl<T> UnwindSafe for LengthLimit<T>where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<R> AsyncReadExt for Rwhere R: AsyncRead + ?Sized,

source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>where Self: Unpin,

Reads some bytes from the byte stream. Read more
source§

fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>] ) -> ReadVectoredFuture<'a, Self>where Self: Unpin,

Like read(), except it reads into a slice of buffers. Read more
source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8, Global> ) -> ReadToEndFuture<'a, Self>where Self: Unpin,

Reads the entire contents and appends them to a Vec. Read more
source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String ) -> ReadToStringFuture<'a, Self>where Self: Unpin,

Reads the entire contents and appends them to a String. Read more
source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>where Self: Unpin,

Reads the exact number of bytes required to fill buf. Read more
source§

fn take(self, limit: u64) -> Take<Self>where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

fn bytes(self) -> Bytes<Self>where Self: Sized,

Converts this [AsyncRead] into a [Stream] of bytes. Read more
source§

fn chain<R>(self, next: R) -> Chain<Self, R>where R: AsyncRead, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
source§

fn boxed_reader<'a>(self) -> Pin<Box<dyn AsyncRead + Send + 'a, Global>>where Self: Sized + Send + 'a,

Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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> LengthLimitExt for Twhere T: AsyncRead + Unpin,

source§

fn limit_bytes(self, max_bytes: usize) -> LengthLimit<Self>

Applies a LengthLimit to self with an exclusive maxiumum of max_bytes bytes
source§

fn limit_kb(self, max_kb: usize) -> LengthLimit<Self>

Applies a LengthLimit to self with an exclusive maxiumum of max_kb kilobytes (defined as 1024 bytes)
source§

fn limit_mb(self, max_mb: usize) -> LengthLimit<Self>

Applies a LengthLimit to self with an exclusive maxiumum of max_mb megabytes (defined as 1024 kilobytes, or 1,048,576 bytes)
source§

fn limit_gb(self, max_gb: usize) -> LengthLimit<Self>

Applies a LengthLimit to self with an exclusive maxiumum of max_gb kilobytes (defined as 1024 megabytes, or 1,073,741,824 bytes)
source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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.