@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.
type HeaderField {
name String
value String
}HeaderField.name#
Field name as written, without the colon.
name StringHeaderField.value#
Field value with leading and trailing space trimmed and folded lines joined by one space.
value StringHeaders Type#
A parsed header block that can be looked up by name regardless of case.
type Headers {
fields List[HeaderField] = List[HeaderField]()
}Headers.fields#
Fields in the order they appeared; repeated names stay separate entries.
fields List[HeaderField] = List[HeaderField]()Headers.get#
Returns the first value for name as a view, ignoring case, or null.
fn get(name String) String?Headers.get_all#
Returns every value for name, ignoring case, in order.
fn get_all(name String) List[String]Headers.to_string#
Formats the block as Name: value lines, each ending in CRLF.
fn to_string() StringMediaType Type#
A parsed media type with lower-cased essence and parameters keyed by lower-cased
name.
type MediaType {
essence String
params Map[String, String] = Map[String, String]()
}MediaType.essence#
Lower-cased type/subtype, such as text/html.
essence StringMediaType.params#
Parameters such as charset or boundary; quoted values are unquoted.
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.
fn to_string() StringPart 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.
type Part {
data Bytes
headers Headers = Headers()
name String = ""
filename String = ""
}Part.data#
Part body without the delimiter line breaks.
data BytesPart.filename#
Uploaded file name from Content-Disposition, or empty text.
filename String = ""Part.headers#
Part header fields; Content-Disposition and Content-Type live here.
headers Headers = Headers()Part.name#
Form field name from Content-Disposition, or empty text.
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.
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.
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.
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.
fn media_type_for_extension(extension String) String? { ... }multipart_boundary Function#
Returns the boundary parameter of a multipart/* Content-Type value, or null.
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.
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.
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.
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.
fn parse_multipart(body Bytes, boundary String) Result[List[Part], Error] { ... }