code wiki / (root) / nx_http_resp.nx

nx_http_resp.nx

buildroot/runtime/nx_http_resp.nx

7294 B204 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic http
docsdependenciesstructsconstsfunctions

about

http_resp.nx -- HTTP/1.1 response generator. Companion to http.nx (request parser). Assembles a valid HTTP response into a caller-mmapped output buffer: status line, headers, body. No internal allocation beyond tiny scratch. Response shape (RFC 7230 ยง3): HTTP-version SP status-code SP reason-phrase CRLF *header-field CRLF CRLF [ message-body ] Implementation notes: - Content-Length automatically emitted from body_len. Chunked transfer encoding is a future extension. - Connection: close emitted by default (no keep-alive yet). - Server: nishi emitted for sovereignty attribution. - Date header NOT emitted -- caller can pre-compute via timefmt.nx if clock sync matters for their use case. Invariants: HR1 Output buffer bounds-checked at every append; overrun returns a negative error rather than silent truncation. HR2 No internal state; each response is built from scratch. Thread-safe for the caller's own isolation concerns. HR3 Status codes + reason phrases kept in a fixed table; no arbitrary int -> string formatting on the response path. HR4 Content-Length header reflects body_len exactly; no mismatched framing that would confuse HTTP/1.1 clients.

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_http_resp.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap http_build_response sys_mmap ↻ http_emit_status http_append_cstr http_append_dec sys_mmap ↻ http_reason http_emit_header http_append_cstr ↻ http_emit_content_length http_append_cstr ↻ http_append_dec ↻ http_append_cstr ↻ http_append_bytes

structs

none

consts

39const HRR_ERR_OVERFLOW: i64 = -1

functions

47func http_reason(code: i64) -> *u8
called by 1: http_emit_status
70func http_append_cstr(out: *u8, pos: *i64, cap: i64, s: *u8) -> i64
83func http_append_bytes(out: *u8, pos: *i64, cap: i64,
called by 1: http_build_response
94func http_append_dec(out: *u8, pos: *i64, cap: i64, n: i64) -> i64
121func http_emit_status(out: *u8, pos: *i64, cap: i64, code: i64) -> i64
135func http_emit_header(out: *u8, pos: *i64, cap: i64,
147func http_emit_content_length(out: *u8, pos: *i64, cap: i64,
163func http_build_response(out: *u8, cap: i64,
194func main() -> i64