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>
impl<S: Stream> ReadTextField<S>
Sourcepub fn limit(self, limit: usize) -> Self
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.
Sourcepub fn limit_max(self) -> Self
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.
Sourcepub fn take_string(&mut self) -> String
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.
Sourcepub fn into_data(self) -> Option<FieldData<S>>
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>
impl<S: Stream> Debug for ReadTextField<S>
Source§impl<S: Default + Stream> Default for ReadTextField<S>
impl<S: Default + Stream> Default for ReadTextField<S>
Source§fn default() -> ReadTextField<S>
fn default() -> ReadTextField<S>
Source§impl<S: Stream> Future for ReadTextField<S>
impl<S: Stream> Future for ReadTextField<S>
Source§type Item = TextField
type Item = TextField
Source§type Error = <S as Stream>::Error
type Error = <S as Stream>::Error
Source§fn poll(&mut self) -> Poll<Self::Item, S::Error>
fn poll(&mut self) -> Poll<Self::Item, S::Error>
Source§fn wait(self) -> Result<Self::Item, Self::Error>where
Self: Sized,
fn wait(self) -> Result<Self::Item, Self::Error>where
Self: Sized,
Source§fn map<F, U>(self, f: F) -> Map<Self, F>
fn map<F, U>(self, f: F) -> Map<Self, F>
Source§fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
fn map_err<F, E>(self, f: F) -> MapErr<Self, F>
Source§fn from_err<E>(self) -> FromErr<Self, E>
fn from_err<E>(self) -> FromErr<Self, E>
From
for
this future’s Error
, returning a new future. Read moreSource§fn then<F, B>(self, f: F) -> Then<Self, B, F>
fn then<F, B>(self, f: F) -> Then<Self, B, F>
f
. Read moreSource§fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F>
Source§fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
fn or_else<F, B>(self, f: F) -> OrElse<Self, B, F>
Source§fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
fn select<B>(self, other: B) -> Select<Self, <B as IntoFuture>::Future>
Source§fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>where
B: IntoFuture,
Self: Sized,
fn select2<B>(self, other: B) -> Select2<Self, <B as IntoFuture>::Future>where
B: IntoFuture,
Self: Sized,
Source§fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
fn join<B>(self, other: B) -> Join<Self, <B as IntoFuture>::Future>
Source§fn join3<B, C>(
self,
b: B,
c: C,
) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
fn join3<B, C>( self, b: B, c: C, ) -> Join3<Self, <B as IntoFuture>::Future, <C as IntoFuture>::Future>
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,
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,
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,
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,
join
, but with more futures.Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll
will never again be called once it has
completed. Read more