nx_pages_static.nx
buildroot/runtime/nx_pages_static.nx
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
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
| 55 | const NXPG_MAGIC_1024: i64 = 1024 |
| 56 | const NXPG_MAGIC_2048: i64 = 2048 |
| 57 | const NXPG_MAGIC_2047: i64 = 2047 |
| 61 | const NXPG_OK: i64 = 0 |
| 62 | const NXPG_NOT_FOUND: i64 = 1 |
| 63 | const NXPG_FORBIDDEN: i64 = 2 |
| 64 | const NXPG_READ_ERR: i64 = 3 |
| 65 | const NXPG_OOM: i64 = 4 |
| 66 | const NXPG_RESPONSE_OOM: i64 = 5 |
| 67 | const NXPG_BAD_ARG: i64 = 6 |
| 68 | const NXPG_METHOD_NOT_ALLOWED: i64 = 7 |
| 69 | const NXPG_VERDICT_N: i64 = 8 |
| 94 | const NXMIME_HTML: i64 = 0 |
| 95 | const NXMIME_CSS: i64 = 1 |
| 96 | const NXMIME_JS: i64 = 2 |
| 97 | const NXMIME_JSON: i64 = 3 |
| 98 | const NXMIME_PNG: i64 = 4 |
| 99 | const NXMIME_JPG: i64 = 5 |
| 100 | const NXMIME_SVG: i64 = 6 |
| 101 | const NXMIME_TXT: i64 = 7 |
| 102 | const NXMIME_ICO: i64 = 8 |
| 103 | const NXMIME_OCTET: i64 = 9 |
| 104 | const NXMIME_N: i64 = 10 |
functions
| 71 | func nxpg_verdict_is_valid(v: i64) -> i64 called by 1: main |
| 77 | func nxpg_verdict_name(v: i64) -> *u8 called by 1: main |
| 107 | func nx_pages_mime_type(m: i64) -> *u8 |
| 121 | func nx_pages_mime_type_len(m: i64) -> i64 called by 1: nxar_serve_audit_cached |
| 135 | func nxpg_ends_with_3(path: *u8, n: i64, a: i64, b: i64, c: i64) -> i64 called by 1: nx_pages_mime_from_path |
| 144 | func nxpg_ends_with_4(path: *u8, n: i64, a: i64, b: i64, c: i64, d: i64) -> i64 called by 1: nx_pages_mime_from_path |
| 154 | func nxpg_ends_with_5(path: *u8, n: i64, called by 1: nx_pages_mime_from_path |
| 166 | func nx_pages_mime_from_path(path: *u8, n: i64) -> i64 |
| 200 | func nxpg_put(out: *u8, off: *i64, cap: i64, b: i64) -> i64 |
| 207 | func nxpg_put_cstr(out: *u8, off: *i64, cap: i64, s: *u8) -> i64 |
| 217 | func nxpg_put_bytes(out: *u8, off: *i64, cap: i64, src: *u8, n: i64) -> i64 |
| 227 | func nxpg_put_dec(out: *u8, off: *i64, cap: i64, v: i64) -> i64 |
| 249 | func nx_pages_emit_200(out: *u8, off: *i64, cap: i64, |
| 265 | func nx_pages_emit_404(out: *u8, off: *i64, cap: i64) -> i64 called by 3: _daemon_serve_onenx_pages_https_handle_connectionnx_pages_serve_file calls 1: nxpg_put_cstr |
| 271 | func nx_pages_emit_403(out: *u8, off: *i64, cap: i64) -> i64 |
| 277 | func nx_pages_emit_405(out: *u8, off: *i64, cap: i64) -> i64 called by 3: _daemon_serve_onenx_pages_https_handle_connectionnx_pages_serve_file calls 1: nxpg_put_cstr |
| 283 | func nx_pages_emit_500(out: *u8, off: *i64, cap: i64) -> i64 |
| 308 | func nx_pages_serve_file(url_path: *u8, url_n: i64, |