multipartkit/form
Types
Opaque builder for multipart/form-data messages.
Form is constructed via new and accumulated with add_field /
add_file / add_file_auto / unsafe_add_part. Read it back as
List(Part) via parts. The boundary is generated lazily by
encode_form and is not part of Form’s observable state.
pub opaque type Form
Values
pub fn add_field(form: Form, name: String, value: String) -> Form
Append a text field. value is encoded as UTF-8 in the part body. No
filename is set.
Carriage returns, line feeds, and NUL bytes in name are silently
stripped to prevent header injection. The cached name on the resulting
Part reflects the sanitized value, matching what a parse-after-encode
round-trip would produce. Use unsafe_add_part if byte-exact
preservation is required.
pub fn add_file(
form: Form,
name: String,
filename: String,
content_type: String,
body: BitArray,
) -> Form
Append a file part with an explicit content type.
Carriage returns, line feeds, and NUL bytes in name, filename, and
content_type are silently stripped to prevent header injection. The
cached name, filename, and content_type on the resulting Part
reflect the sanitized values. Use unsafe_add_part if byte-exact
preservation is required.
pub fn add_file_auto(
form: Form,
name: String,
filename: String,
body: BitArray,
) -> Form
Append a file part using the default (no-op) inferer.
Equivalent to add_file_auto_with(form, name, filename, body, infer.default_inferer()). The default inferer returns None from both
helpers in v0.1.0, so this falls through to application/octet-stream
unless you call add_file_auto_with with a real inferer.
pub fn add_file_auto_with(
form: Form,
name: String,
filename: String,
body: BitArray,
inferer: infer.Inferer,
) -> Form
Append a file part, inferring the content type via the supplied
Inferer.
Inference precedence:
inferer.from_filename(filename)inferer.from_bytes(body)application/octet-stream
The inferred content type is sanitized (CR / LF / NUL stripped) before being written to the header.
pub fn unsafe_add_part(form: Form, the_part: part.Part) -> Form
Append a pre-built Part without validation or normalisation.
The caller is responsible for keeping headers, name, filename, and
content_type mutually consistent. Prefer add_field / add_file /
add_file_auto for library-maintained consistency.