code wiki / (root) / nx_pages_static.nx

nx_pages_static.nx

buildroot/runtime/nx_pages_static.nx

15097 B411 linesdepth 2pulls 3 transitivereach 7 importersview sourcekind librarytopic pages
docsdependenciesstructsconstsfunctions

about

nx_pages_static.nx -- static-file serving over nx_http_server. Closes the LAST gap between today's CLI scripts and a live audit dashboard at http://localhost:PORT/audit. Composes the existing substrate: nx_path_canonicalize.nx -- CWE-22 prevention at the URL boundary nx_http_server.nx -- bind/listen/accept loop nx_http_resp.nx -- response builder sys_read_file_x86_64 -- file I/O The full live-dashboard chain (Phase 2 of NISHI_AUDIT_DASHBOARD_ ROADMAP.md) is now operational with this primitive. What this primitive provides: - nx_pages_serve_file(url_path, url_n, base_dir, base_n, ...) Reads docs/audit/index.html (or any file under base_dir) + emits an HTTP/1.1 200 response with proper Content-Type derived from extension. - MIME-type table (sealed enum + lookup): html, css, js, json, png, jpg, svg, txt, ico, plus "application/octet-stream" fallback for unknown extensions. - Sealed-enum verdict (8 states): OK / NOT_FOUND / FORBIDDEN / READ_ERR / OOM / RESPONSE_OOM / BAD_ARG / METHOD_NOT_ALLOWED. Per cardinal user-owns-every-bit: - Caller supplies base_dir; primitive never picks "well-known" paths. - Caller supplies response buffer + max size. - No implicit caching, no mmap'd inode store, no auto-index. If URL is `/`, primitive returns NOT_FOUND -- caller must explicitly route `/` to a specific file. Per cardinal feedback-defensive-at-boundaries-trusting-internally: url_path is canonicalized ONCE at entry; subsequent file-open uses the canonical path; no re-validation.

dependencies 2 imports · 7 importers

nx_syscalls.nx nx_path_canonicalize.nx nx_pages_static.nx nx_audit_server_daemon.nx nx_audit_server_main.nx nx_audit_server_routed.nx nx_browser_view_serve.nx nx_pages_daemon.nx nx_pages_https_daemon.nx nx_pages_static_test.nx

imports: nx_syscalls.nxnx_path_canonicalize.nx

imported by: nx_audit_server_daemon.nxnx_audit_server_main.nxnx_audit_server_routed.nxnx_browser_view_serve.nxnx_pages_daemon.nxnx_pages_https_daemon.nxnx_pages_static_test.nx

structs

none

consts

55const NXPG_MAGIC_1024: i64 = 1024
56const NXPG_MAGIC_2048: i64 = 2048
57const NXPG_MAGIC_2047: i64 = 2047
61const NXPG_OK: i64 = 0
62const NXPG_NOT_FOUND: i64 = 1
63const NXPG_FORBIDDEN: i64 = 2
64const NXPG_READ_ERR: i64 = 3
65const NXPG_OOM: i64 = 4
66const NXPG_RESPONSE_OOM: i64 = 5
67const NXPG_BAD_ARG: i64 = 6
68const NXPG_METHOD_NOT_ALLOWED: i64 = 7
69const NXPG_VERDICT_N: i64 = 8
94const NXMIME_HTML: i64 = 0
95const NXMIME_CSS: i64 = 1
96const NXMIME_JS: i64 = 2
97const NXMIME_JSON: i64 = 3
98const NXMIME_PNG: i64 = 4
99const NXMIME_JPG: i64 = 5
100const NXMIME_SVG: i64 = 6
101const NXMIME_TXT: i64 = 7
102const NXMIME_ICO: i64 = 8
103const NXMIME_OCTET: i64 = 9
104const NXMIME_N: i64 = 10

functions

71func nxpg_verdict_is_valid(v: i64) -> i64
called by 1: main
77func nxpg_verdict_name(v: i64) -> *u8
called by 1: main
107func nx_pages_mime_type(m: i64) -> *u8
121func nx_pages_mime_type_len(m: i64) -> i64
135func nxpg_ends_with_3(path: *u8, n: i64, a: i64, b: i64, c: i64) -> i64
144func nxpg_ends_with_4(path: *u8, n: i64, a: i64, b: i64, c: i64, d: i64) -> i64
154func nxpg_ends_with_5(path: *u8, n: i64,
166func nx_pages_mime_from_path(path: *u8, n: i64) -> i64
200func nxpg_put(out: *u8, off: *i64, cap: i64, b: i64) -> i64
207func nxpg_put_cstr(out: *u8, off: *i64, cap: i64, s: *u8) -> i64
217func nxpg_put_bytes(out: *u8, off: *i64, cap: i64, src: *u8, n: i64) -> i64
called by 1: nx_pages_emit_200 calls 1: nxpg_put
227func nxpg_put_dec(out: *u8, off: *i64, cap: i64, v: i64) -> i64
called by 1: nx_pages_emit_200 calls 2: nxpg_putsys_mmap
249func nx_pages_emit_200(out: *u8, off: *i64, cap: i64,
265func nx_pages_emit_404(out: *u8, off: *i64, cap: i64) -> i64
271func nx_pages_emit_403(out: *u8, off: *i64, cap: i64) -> i64
called by 1: nx_pages_serve_file calls 1: nxpg_put_cstr
277func nx_pages_emit_405(out: *u8, off: *i64, cap: i64) -> i64
283func nx_pages_emit_500(out: *u8, off: *i64, cap: i64) -> i64
called by 1: nx_pages_serve_file calls 1: nxpg_put_cstr
308func nx_pages_serve_file(url_path: *u8, url_n: i64,