Skip to main content

Module multipart

Module multipart 

Source
Expand description

In-memory multipart/form-data bodies (RFC 7578 over RFC 2046 framing).

The boundary is derived from 16 bytes of entropy the host supplies (this crate reads no randomness source) and is then checked against every part: a boundary that occurs anywhere in a part’s name, filename, content type or bytes is replaced by the next candidate, so no payload - base64 text with a boundary-shaped run included - can end a part early.

use turnloop_http::multipart::{Form, Part};
let form = Form::new()
    .text("version", "1.2.0")
    .part(Part::file("tarball", "pkg.tgz", b"\x1f\x8b...".to_vec()).content_type("application/gzip"));
let encoded = form.encode([7; 16]).unwrap();
assert!(encoded.content_type().starts_with("multipart/form-data; boundary="));

Structs§

Encoded
An encoded form body and the boundary its Content-Type must name.
Form
An ordered list of parts, encoded in one piece by Form::encode.
Part
One form field: a text value or a named file.