Media types
media_type reads Content-Type into an essence and ordered parameters, then writes it back with correct quoting.
Media types, Content-Disposition, multipart bodies, form uploads — parsed and written from bytes, whole or a piece at a time. No sockets, no files, no globals.
This widget calls the real library, compiled to JavaScript and running in this page.
One package, eleven jobs. Each takes a header or a body and hands back data you can act on — and two of them hand a body back, or take one in pieces.
media_type reads Content-Type into an essence and ordered parameters, then writes it back with correct quoting.
guess_type names the type a filename implies; guess_extension gives the extension people use for a type.
Build and parse the header that names a download, with filename* (RFC 5987) for names that escape ASCII.
multipart splits any multipart body into parts — the shape an email and a form upload share.
formdata reads multipart/form-data into text fields and file uploads, distinguishing them the way the wire does.
Form::encode and Multipart::new frame parts the way a browser or a mail client does, with a boundary proven absent and filename* for names that leave ASCII.
PartsReader gives a part's headers before its body and the body a chunk at a time, with the bound holding as it reads; MultipartWriter frames one part at a time into a sink.
Related frames multipart/related (RFC 2387) with type, start and start-info, and reads start back into the part it names.
encode_words writes a header value as RFC 2047 words, B or Q, split so none passes 75 characters; decode_words reads any mix back.
moonmime/qp encodes and decodes a body (RFC 2045 §6.7): soft breaks at 76 columns, =XY escapes, trailing whitespace protected.
Limits caps part count and part size. A body over its bound is refused whole, never truncated.
moon add moonbitstack/moonmime
let mt = @moonmime.media_type("text/html; charset=utf-8")
println(mt.essence)
println(mt.type_())
println(mt.param("charset").unwrap_or(""))