Struct ReadTextField

Source
pub struct ReadTextField<S: Stream> {
    pub headers: Rc<FieldHeaders>,
    pub limit: usize,
    /* private fields */
}
Expand description

A Future which attempts to read a field’s data to a string.

§Charset

For simplicity, the default UTF-8 character set is assumed, as defined in IETF RFC 7578 Section 5.1.2. If the field body cannot be decoded as UTF-8, an error is returned.

Decoding text in a different charset (except ASCII which is compatible with UTF-8) is, currently, beyond the scope of this crate. However, as a convention, web browsers will send multipart/form-data requests in the same charset as that of the document (page or frame) containing the form, so if you only serve ASCII/UTF-8 pages then you won’t have to worry too much about decoding strange charsets.

§Warning About Leaks

If this value or the contained FieldData is leaked (via mem::forget() or some other mechanism), then the parent Multipart will never be able to yield the next field in the stream. The task waiting on the Multipart will also never be notified, which, depending on the event loop/reactor/executor implementation, may cause a deadlock.

Fields§

§headers: Rc<FieldHeaders>

The headers for the original field, provided as a convenience.

§limit: usize

The limit for the string, in bytes, to avoid potential DoS attacks from attackers running the server out of memory. If an incoming chunk is expected to push the string over this limit, an error is returned and the offending chunk is pushed back to the head of the stream.

Implementations§

Source§

impl<S: Stream> ReadTextField<S>

Source

pub fn limit(self, limit: usize) -> Self

Set the length limit, in bytes, for the collected text. If an incoming chunk is expected to push the string over this limit, an error is returned and the offending chunk is pushed back to the head of the stream.

Setting a value higher than a few megabytes is not recommended as it could allow an attacker to DoS the server by running it out of memory, causing it to panic on allocation or spend forever swapping pagefiles to disk. Remember that this limit is only for a single field as well.

Setting this to usize::MAX is equivalent to removing the limit as the string would overflow its capacity value anyway.

Source

pub fn limit_max(self) -> Self

Soft max limit if the default isn’t large enough.

Going higher than this is allowed, but not recommended.

Source

pub fn take_string(&mut self) -> String

Take the text that has been collected so far, leaving an empty string in its place.

If the length limit was hit, this allows the field to continue being read.

Source

pub fn ref_text(&self) -> &str

The text that has been collected so far.

Source

pub fn into_data(self) -> Option<FieldData<S>>

Destructure this future, taking the internal FieldData instance back.

Will be None if the field was read to completion, because the internal FieldData instance is dropped afterwards to allow the parent Multipart to immediately start working on the next field.

Trait Implementations§

Source§

impl<S: Stream> Debug for ReadTextField<S>

Source§

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

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

impl<S: Default + Stream> Default for ReadTextField<S>

Source§

fn default() -> ReadTextField<S>

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

impl<S: Stream> Future for ReadTextField<S>

Source§

type Item = TextField

The type of value that this future will resolved with if it is successful.
Source§

type Error = <S as Stream>::Error

The type of error that this future will resolve with if it fails in a normal fashion.
Source§

fn poll(&mut self) -> Poll<Self::Item, S::Error>

Query this future to see if its value has become available, registering interest if it is not. Read more
Source§

fn wait(self) -> Result<Self::Item, Self::Error>
where Self: Sized,

Block the current thread until this future is resolved. Read more
Source§

fn map<F, U>(self, f: F) -> Map<Self, F>
where F: FnOnce(Self::Item) -> U, Self: Sized,

Map this future’s result to a different type, returning a new future of the resulting type. Read more
Source§

fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
where F: FnOnce(Self::Error) -> E, Self: Sized,

Map this future’s error to a different error, returning a new future. Read more
Source§

fn from_err<E>(self) -> FromErr<Self, E>
where E: From<Self::Error>, Self: Sized,

Map this future’s error to any error implementing From for this future’s Error, returning a new future. Read more
Source§

fn then<F, B>(self, f: F) -> Then<Self, B, F>
where F: FnOnce(Result<Self::Item, Self::Error>) -> B, B: IntoFuture, Self: Sized,

Chain on a computation for when a future finished, passing the result of the future to the provided closure f. Read more
Source§

fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
where F: FnOnce(Self::Item) -> B, B: IntoFuture<Error = Self::Error>, Self: Sized,

Execute another future after this one has resolved successfully. Read more
Source§

fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
where F: FnOnce(Self::Error) -> B, B: IntoFuture<Item = Self::Item>, Self: Sized,

Execute another future if this one resolves with an error. Read more
Source§

fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
where B: IntoFuture<Item = Self::Item, Error = Self::Error>, Self: Sized,

Waits for either one of two futures to complete. Read more
Source§

fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>
where B: IntoFuture, Self: Sized,

Waits for either one of two differently-typed futures to complete. Read more
Source§

fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
where B: IntoFuture<Error = Self::Error>, Self: Sized,

Joins the result of two futures, waiting for them both to complete. Read more
Source§

fn join3<B, C>( self, b: B, c: C, ) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
where B: IntoFuture<Error = Self::Error>, C: IntoFuture<Error = Self::Error>, Self: Sized,

Same as join, but with more futures.
Source§

fn join4<B, C, D>( self, b: B, c: C, d: D, ) -> Join4<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future>
where B: IntoFuture<Error = Self::Error>, C: IntoFuture<Error = Self::Error>, D: IntoFuture<Error = Self::Error>, Self: Sized,

Same as join, but with more futures.
Source§

fn join5<B, C, D, E>( self, b: B, c: C, d: D, e: E, ) -> Join5<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future, <D as IntoFuture>::Future, <E as IntoFuture>::Future>
where B: IntoFuture<Error = Self::Error>, C: IntoFuture<Error = Self::Error>, D: IntoFuture<Error = Self::Error>, E: IntoFuture<Error = Self::Error>, Self: Sized,

Same as join, but with more futures.
Source§

fn into_stream(self) -> IntoStream<Self>
where Self: Sized,

Convert this future into a single element stream. Read more
Source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Fuse a future such that poll will never again be called once it has completed. Read more
Source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where F: FnOnce(&Self::Item), Self: Sized,

Do something with the item of a future, passing it on. Read more
Source§

fn catch_unwind(self) -> CatchUnwind<Self>
where Self: Sized + UnwindSafe,

Catches unwinding panics while polling the future. Read more
Source§

fn shared(self) -> Shared<Self>
where Self: Sized,

Create a cloneable handle to this future where all handles will resolve to the same result. Read more

Auto Trait Implementations§

§

impl<S> Freeze for ReadTextField<S>

§

impl<S> !RefUnwindSafe for ReadTextField<S>

§

impl<S> !Send for ReadTextField<S>

§

impl<S> !Sync for ReadTextField<S>

§

impl<S> Unpin for ReadTextField<S>

§

impl<S> !UnwindSafe for ReadTextField<S>

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> FutureExt for T
where T: Future + ?Sized,

Source§

fn timeout(self, timeout: Duration) -> Timeout<Self>
where Self: Sized,

Creates a new future which allows self until timeout. Read more
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<F> IntoFuture for F
where F: Future,

Source§

type Future = F

The future that this type can be converted into.
Source§

type Item = <F as Future>::Item

The item that the future may resolve with.
Source§

type Error = <F as Future>::Error

The error that the future may resolve with.
Source§

fn into_future(self) -> F

Consumes this object and produces a future.
Source§

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

Source§

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 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.