Skip to main content

Module write

Module write 

Source
Expand description

Serialization: the cached Date, pre-serialized heads, a head writer and the chunked encoder. Everything writes into caller-owned buffers or returns small stack values, so a response can go out as one writev: head, body, and for chunked bodies the chunk header and the CRLF around each piece.

Structs§

ChunkHeader
A chunk header, <hex length>\r\n, on the stack.
DateCache
The Date value, formatted once per second. The caller owns the clock: call update with the current Unix time, typically once per loop tick.
HeadWriter
Writes a message head into a caller-owned buffer (reuse it to avoid allocation). Field names and values are validated, so a value cannot split the response; framing goes through content_length and chunked only.
StaticHead
A response serialized once, with a Date slot patched at most once a second: the fast path for fixed replies. The body (possibly empty) follows the head in the same buffer, so the whole reply is one slice.

Constants§

CONTINUE
HTTP/1.1 100 Continue with its empty line.
CRLF
The CRLF that ends each chunk’s data.
LAST_CHUNK
The last chunk with no trailers.

Functions§

http_date
The IMF-fixdate for a Unix time, e.g. Sun, 06 Nov 1994 08:49:37 GMT (RFC 9110 §5.6.7).
reason
The reason phrase for a status code (empty for codes without one).
write_chunk
Appends one chunk (header, data, CRLF). Empty data writes nothing, since an empty chunk would end the body.
write_last_chunk
Appends the last chunk, the trailer fields and the final empty line.