Skip to main content

Module wire

Module wire 

Source
Expand description

Gemini wire format: request validation, the response header, and gemtext rendering.

Pure functions, shared by the session loop, the action executor and the tests. The model supplies a status, a line of meta and structured gemtext lines; everything that makes a Gemini response well-formed — the two-digit code, the single space, the CRLF, the 1024-byte meta bound, the body appearing only after a 2x, and gemtext line prefixes that cannot be confused with one another — is decided here.

Structs§

GeminiRequest
A request that passed validation, as the model sees it.

Enums§

GemtextError
Why a gemtext line could not be rendered.
GemtextLine
One gemtext line as the model supplies it.
RequestRefusal
Why a request line was refused before reaching the model, with the response it gets.
ResponseError
Why a response could not be rendered.

Constants§

GEMTEXT_MIME
The MIME type NetGet’s rendered gemtext declares.
MAX_META_BYTES
The longest meta field a response may carry (§“Responses”: META MUST NOT exceed 1024 bytes).
MAX_REQUEST_BYTES
The longest request line this server buffers: MAX_URL_BYTES plus CRLF. This is the declared max_inbound_bytes — a client sends nothing else on a connection.
MAX_URL_BYTES
The longest URL a request may carry, in bytes, excluding its CRLF.
STATUS_CODES
Every status code the specification defines, with the meta a response gets when the model leaves it empty. A response header is always <code> <meta> with a non-empty meta: some clients split the header on whitespace and fail outright on a bare 51\r\n.

Functions§

gemtext_mime
A lang parameter for the gemtext MIME type: BCP 47 tags, comma-separated. Anything else is dropped rather than written into the header.
leading_status
The two-digit status a rendered response begins with.
parse_request
Validate a request line (without its CRLF).
percent_decode
Decode %XX escapes (and nothing else — + is a plus sign in a Gemini query, which is not form encoding). Invalid escapes are kept literally; invalid UTF-8 is replaced.
render_gemtext
Render gemtext. Every line ends in LF, which the specification allows and every client reads.
render_response
Render a complete response: header, and the body only for a 2x.