pub struct Multipart<S>{ /* private fields */ }Expand description
A streaming parser for multipart/form-data.
The parser owns the underlying stream and yields one Part at a time.
At most one Part is active at any moment; the borrow checker enforces
this property at compile time.
The stream has to be Send + Unpin, but not Sync: the parser only ever
polls it through &mut, so it never needs shared access, and requiring
Sync would turn away streams that can be moved between threads but not
shared between them.
Implementations§
Source§impl<S> Multipart<S>
impl<S> Multipart<S>
Sourcepub fn new(stream: S, boundary: &Boundary, max_buffer_size: usize) -> Self
pub fn new(stream: S, boundary: &Boundary, max_buffer_size: usize) -> Self
Constructs a parser.
max_buffer_size bounds the part header block: a block that ends within
the limit is accepted, and one that grows past it without a terminator is
rejected with Error::HeaderSizeExceeded. The limit is a property of
the body, not of the delivery — the same bytes parse the same way however
the transport splits them — so a chunk larger than max_buffer_size
carrying a block that ends within the limit is accepted.
Data chunks yielded by stream while part data is being streamed are
passed through without being retained, so they are not charged to this
limit. The buffer can still hold one arriving chunk beyond the limit: the
bytes that follow the header terminator are retained until the header
block is consumed, so the limit bounds the block, not the peak allocation.
Sourcepub async fn next_part(&mut self) -> Result<Option<Part<'_, S>>, Error>
pub async fn next_part(&mut self) -> Result<Option<Part<'_, S>>, Error>
Returns the next part, or None after the closing delimiter.
Dropping a Part without entering its data phase (through
Part::next_data or Part::take_data_stream) skips the rest of
that part: unread headers are discarded and the part’s data is skipped
lazily, so a caller can leave a part behind and keep going.
§Errors
Returns an error for malformed input, stream errors, or when the multipart stream has already been taken by a part data stream.
Sourcepub fn poll_next_part(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<Option<Part<'_, S>>, Error>>
pub fn poll_next_part( &mut self, cx: &mut Context<'_>, ) -> Poll<Result<Option<Part<'_, S>>, Error>>
Poll-based core of the state machine, driven by Multipart::next_part.