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>
impl<R: Read> MultipartReader<R>
Sourcepub fn with_limits(
content_type: &[u8],
reader: R,
limits: &Limits,
policy: &Policy,
) -> Result<Self, FormError>
pub fn with_limits( content_type: &[u8], reader: R, limits: &Limits, policy: &Policy, ) -> Result<Self, FormError>
Sourcepub fn captured_token(&self) -> Option<&str>
pub fn captured_token(&self) -> Option<&str>
The token field’s value, once its part has ended.
Sourcepub fn next_part(&mut self) -> Result<Option<PartReader<'_, R>>, FormError>
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>
impl<R: Read> Debug for MultipartReader<R>
Source§impl<R: Read> Drop for MultipartReader<R>
impl<R: Read> Drop for MultipartReader<R>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more