multra
An async parser for multipart/form-data content-type in Rust. Forked from multer.
It accepts a Stream of Bytes as
a source, so that It can be plugged into any async Rust environment e.g. any async server.
Install
Add this to your Cargo.toml:
[]
= "1"
Basic Example
use Bytes;
use Stream;
// Import multra types.
use ;
use Infallible;
use once;
async
// Generate a byte stream and the boundary from somewhere e.g. server request body.
async
Multipart::new() and Multipart::with_reader() keep backward-compatible unbounded
size limits. For untrusted uploads, prefer the constrained constructors.
Use Multipart::try_new() or Multipart::try_with_constraints() when the
boundary has not already been validated by multra::parse_boundary().
The preamble limit defaults to 32 KiB and can be changed with
SizeLimit::preamble() when MIME compatibility requires a larger value.
Each boundary's transport padding (spaces and tabs following its marker) is
limited to 8 KiB by default, independently of field and whole-stream limits.
Use SizeLimit::boundary_padding() to adjust this limit. This applies to
opening, intermediate, and closing boundaries; excess padding returns
Error::BoundaryPaddingSizeExceeded rather than being treated as field data.
To reject bodies containing too many parts, set a field count limit as well:
let constraints = new.max_fields;
The count includes empty fields, repeated names, and fields skipped without
reading. The next part beyond the limit returns Error::FieldCountExceeded
before its headers are parsed. Field count remains unbounded by default.
Prevent Denial of Service (DoS) Attacks
This crate provides APIs to prevent potential DoS attacks with fine grained control. The default constructors leave stream and field size limits unbounded, so it is recommended to add explicit constraints for untrusted multipart bodies.
An example:
use Bytes;
use once;
use ;
use Infallible;
async
Usage with hyper.rs server
An example showing usage with hyper.rs.
For more examples, please visit examples.
Contributing
Your PRs and suggestions are always welcome.