Skip to main content

MultipartReader

Struct MultipartReader 

Source
pub struct MultipartReader<R: Read> { /* private fields */ }
Available on crate feature std only.
Expand description

Reads a multipart body from a blocking reader, one part at a time.

It has no hooks: the caller sees each part itself. Dropping a PartReader before its end skips the rest of the part at the next next_part.

§Examples

use std::io::Read;

let body = b"--X\r\nContent-Disposition: form-data; name=note\r\n\r\nhi\r\n--X\r\nContent-Disposition: form-data; name=f; filename=a.bin\r\n\r\n0123\r\n--X--";
let mut reader = form_net::MultipartReader::new(b"multipart/form-data; boundary=X", &body[..])?;
let mut seen = Vec::new();
while let Some(mut part) = reader.next_part()? {
    if part.head().view().is_file() {
        let mut bytes = Vec::new();
        part.read_to_end(&mut bytes).unwrap();
        seen.push(bytes.len());
    } else {
        seen.push(part.text()?.len());
    }
}
assert_eq!(seen, [2, 4]);

Implementations§

Source§

impl<R: Read> MultipartReader<R>

Source

pub fn new(content_type: &[u8], reader: R) -> Result<Self, FormError>

A reader with the default limits and policy.

§Errors

UnsupportedMediaType and the boundary errors.

Source

pub fn with_limits( content_type: &[u8], reader: R, limits: &Limits, policy: &Policy, ) -> Result<Self, FormError>

A reader with explicit limits and policy.

§Errors

As new; InvalidLimits.

Source

pub fn captured_token(&self) -> Option<&str>

The token field’s value, once its part has ended.

Source

pub fn next_part(&mut self) -> Result<Option<PartReader<'_, R>>, FormError>

The next part, or None after the close delimiter. Skips whatever is left of the previous part. After the close delimiter it reads the rest of the body, which is epilogue and counts against max_epilogue_bytes and max_body_bytes, as parse_multipart counts it (D-142).

§Errors

Every multipart error; Io { kind } from the reader.

Trait Implementations§

Source§

impl<R: Read> Debug for MultipartReader<R>

Source§

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

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

impl<R: Read> Drop for MultipartReader<R>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<R> Forget for MultipartReader<R>

§

impl<R> Freeze for MultipartReader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for MultipartReader<R>
where R: RefUnwindSafe,

§

impl<R> Send for MultipartReader<R>
where R: Send,

§

impl<R> Sync for MultipartReader<R>
where R: Sync,

§

impl<R> Unpin for MultipartReader<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for MultipartReader<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for MultipartReader<R>
where R: UnwindSafe,

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.