nx_http_resp.nx
buildroot/runtime/nx_http_resp.nx
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
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
structs
| none |
consts
| 39 | const HRR_ERR_OVERFLOW: i64 = -1 |
functions
| 47 | func http_reason(code: i64) -> *u8 called by 1: http_emit_status |
| 70 | func http_append_cstr(out: *u8, pos: *i64, cap: i64, s: *u8) -> i64 |
| 83 | func http_append_bytes(out: *u8, pos: *i64, cap: i64, called by 1: http_build_response |
| 94 | func http_append_dec(out: *u8, pos: *i64, cap: i64, n: i64) -> i64 |
| 121 | func http_emit_status(out: *u8, pos: *i64, cap: i64, code: i64) -> i64 |
| 135 | func http_emit_header(out: *u8, pos: *i64, cap: i64, |
| 147 | func http_emit_content_length(out: *u8, pos: *i64, cap: i64, |
| 163 | func http_build_response(out: *u8, cap: i64, |
| 194 | func main() -> i64 |