Manuscript Documentation
v2026.12.0

@std/net/mime.ms#

Import each required symbol with import Name from "@std/net/mime.ms".

HeaderField Type#

One header field. name keeps the sender’s spelling; value has folding removed.

Manuscript
type HeaderField {
    name String
    value String
}

HeaderField.name#

Field name as written, without the colon.

Manuscript
name String

HeaderField.value#

Field value with leading and trailing space trimmed and folded lines joined by one space.

Manuscript
value String

Headers Type#

A parsed header block that can be looked up by name regardless of case.

Manuscript
type Headers {
    fields List[HeaderField] = List[HeaderField]()
}

Headers.fields#

Fields in the order they appeared; repeated names stay separate entries.

Manuscript
fields List[HeaderField] = List[HeaderField]()

Headers.get#

Returns the first value for name as a view, ignoring case, or null.

Manuscript
fn get(name String) String?

Headers.get_all#

Returns every value for name, ignoring case, in order.

Manuscript
fn get_all(name String) List[String]

Headers.to_string#

Formats the block as Name: value lines, each ending in CRLF.

Manuscript
fn to_string() String

MediaType Type#

A parsed media type with lower-cased essence and parameters keyed by lower-cased name.

Manuscript
type MediaType {
    essence String
    params Map[String, String] = Map[String, String]()
}

MediaType.essence#

Lower-cased type/subtype, such as text/html.

Manuscript
essence String

MediaType.params#

Parameters such as charset or boundary; quoted values are unquoted.

Manuscript
params Map[String, String] = Map[String, String]()

MediaType.to_string#

Formats the media type as essence; name=value, quoting values that are not simple tokens.

Manuscript
fn to_string() String

Part Type#

One multipart part: its headers, the name and filename from Content-Disposition, and body bytes. The two names are read as browsers write them: a quoted value is literal, a backslash included, and a quote in it is %22.

Manuscript
type Part {
    data Bytes
    headers Headers = Headers()
    name String = ""
    filename String = ""
}

Part.data#

Part body without the delimiter line breaks.

Manuscript
data Bytes

Part.filename#

Uploaded file name from Content-Disposition, or empty text.

Manuscript
filename String = ""

Part.headers#

Part header fields; Content-Disposition and Content-Type live here.

Manuscript
headers Headers = Headers()

Part.name#

Form field name from Content-Disposition, or empty text.

Manuscript
name String = ""

encode_multipart Function#

Encodes parts as a multipart body closed with the final delimiter. Each part’s headers are written as given, then a blank line and the data. A boundary, header name or header value holding CR, LF or NUL would start a new line in the body, so it returns EINVAL instead.

Manuscript
fn encode_multipart(parts List[Part], boundary String) Result[Bytes, Error] { ... }

extension_for_media_type Function#

Returns the first extension, with its dot, registered for a media type (parameters ignored), or null.

Manuscript
fn extension_for_media_type(media_type String) String? { ... }

form_part Function#

Builds a form-data part for a field; pass filename to mark an upload.

Manuscript
fn form_part(name String, move data Bytes, filename String = "", content_type String = "") Part { ... }

media_type_for_extension Function#

Returns the media type for a file extension, with or without the leading dot and in any case, or null when unknown. Text types include charset=utf-8, as in text/html; charset=utf-8.

Manuscript
fn media_type_for_extension(extension String) String? { ... }

multipart_boundary Function#

Returns the boundary parameter of a multipart/* Content-Type value, or null.

Manuscript
fn multipart_boundary(content_type String) String? { ... }

multipart_parts Function#

Reads the parts of a multipart body from a byte stream, one at a time, for uploads too big to hold in memory. Parts are built as parse_multipart builds them, and only the part being read is buffered. max_part_bytes bounds one part’s headers and body and fails the read with EOVERFLOW. A body that ends without its closing delimiter fails with EBADMSG. Closing the result closes body.

Manuscript
fn multipart_parts(move body ReadStream[Bytes], boundary String, max_part_bytes Int? = null) ReadStream[Part] { ... }

parse_headers Function#

Parses a header block (up to the first blank line). Continuation lines starting with space or tab join the previous value with one space. A line without a colon, or a fold before any field, returns EBADMSG.

Manuscript
fn parse_headers(text String) Result[Headers, Error] { ... }

parse_media_type Function#

Parses type/subtype; name=value; name="quoted value". Names and the essence are lower-cased. A missing slash, an empty part, a parameter without =, or an unterminated quote returns EBADMSG.

Manuscript
fn parse_media_type(text String) Result[MediaType, Error] { ... }

parse_multipart Function#

Splits a multipart body into parts using boundary. Text before the first delimiter and after the closing delimiter is ignored. Parts keep their body bytes exactly; headers are parsed as Headers. A part may be only headers, or empty. A body without a closing delimiter returns EBADMSG.

Manuscript
fn parse_multipart(body Bytes, boundary String) Result[List[Part], Error] { ... }