Expand description
An implementation of the Nex protocol
(nex://, TCP port 1900): an async client, a directory-serving server, a
listing parser, and a small CLI.
Nex is the minimal smolweb protocol, from nightfall.city, inspired by
gopher and gemini. The whole wire format: the client connects and sends a
path (which may be empty); the server responds with text or binary data
and closes the connection. No TLS, no status codes, no headers, no state.
Directory content is plain text where each line beginning => followed
by a URL is a link; an empty path or a path ending in / is a directory;
a document’s display type follows its file extension, defaulting to plain
text.
This crate is independent and unaffiliated with the protocol’s author.
The crates.io name is qualified (nex-protocol) because the bare nex
name is used by an unrelated project.
let body = nex_protocol::fetch("nex://nightfall.city/", &Default::default()).await?;
println!("{}", String::from_utf8_lossy(&body));Structs§
- Fetch
Options - Options for a
fetch. - File
Handler - A static-directory
Handler. Directory selectors (empty or trailing/) serve a generated listing, or the directory’sindex.nexfile when present. Traversal out of the root is refused with a plain-text message. - Request
- One nex request: the selector path, exactly as sent (CR/LF trimmed).
- Server
Config - Server limits and timeouts.
Enums§
- Client
Error - Why a fetch failed. Nex has no protocol-level errors: a successful exchange is whatever bytes the server sent.
- Listing
Line - One line of a directory listing.
Constants§
- NEX_
PORT - Nex’s port (“Afterall, night falls at 7pm!”).
Traits§
- Handler
- The application seam: turn a
Requestinto response bytes. Nex has no status codes, so “not found” is whatever text the handler chooses.
Functions§
- fetch
- Fetch a
nex://URL and return the raw response bytes. - fetch_
path - Fetch by explicit host/port/path. The path may be empty (the spec allows an empty selector for the root).
- is_
directory_ path - Whether a request path names a directory, per the spec: an empty path or
one ending in
/. - parse_
listing - Parse a directory listing into its lines.
- serve
- Accept connections on
listenerand serve them throughhandleruntilshutdownresolves.