code wiki / _hdl_build / nx_host_router.nx
nx_host_router.nx
buildroot/runtime/_hdl_build/nx_host_router.nx
about
nx_host_router.nx -- S-class sovereign multi-site host router (pure Nishi, no TLS, no crypto).
Config-driven vhost table + PER-REQUEST file serving = HOT CONTENT LOADING: push a file, it is
live on the next request, NO recompile. Path-traversal-safe. This is L5 (content) of the sovereign
hosting design (knowledge/research/2026-06-05-sovereign-web-hosting.md). Composed into the TLS
daemon, which supplies L3/L4. license_tier: ORIGINAL
dependencies 4 imports · 7 importers
imports: nx_syscalls.nxnx_fio.nxnx_range_header.nxnx_gzip_lib.nx
imported by: nx_host_range_gate.nxnx_host_router2_test.nxnx_host_router_gate.nxnx_host_router_test.nxnx_hr_serve3_slot_gate.nxnx_sites_daemon.nxnx_sites_daemon_v2.nx
structs
| none |
consts
| 9 | const HR_S2_FILE_STREAM: i64 = 6 |
| 17 | const HR_MAGIC_9216: i64 = 9216 |
| 18 | const HR_MAGIC_8192: i64 = 8192 |
| 19 | const HR_MAGIC_1024: i64 = 1024 |
| 20 | const HR_MAGIC_4096: i64 = 4096 |
| 21 | const HR_MAGIC_5120: i64 = 5120 |
| 22 | const HR_MAGIC_2048: i64 = 2048 |
| 23 | const HR_MAGIC_4095: i64 = 4095 |
| 331 | const HR_ASSET_MAXAGE: i64 = 3600 |
| 447 | const HR_S2_MISS: i64 = 0 // host known but file absent -> caller falls through to legacy routing |
| 448 | const HR_S2_OK: i64 = 1 // 200 written |
| 449 | const HR_S2_BAD: i64 = 2 // 400 written (traversal/malformed) |
| 450 | const HR_S2_TOOBIG: i64 = 3 // 500 written (file exceeds outcap) |
| 505 | const HR_S2_REDIR: i64 = 4 // 301 written to out (out_n set); caller must NOT fall through |
| 506 | const HR_S2_STREAM: i64 = 5 // headers written to out; BODY handed via hr_stream_body/bodyn -- the |
| 689 | const HR_SLOT_MARK: *u8 = "<!--nx-ad-slot-->" as *u8 |
functions
| 25 | func hr_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 27 | func hr_copy(dst: *u8, src: *u8, n: i64) -> i64 { var i: i64 = 0; while i < n { dst[i] = src[i]; i = i + 1 } return n } |
| 29 | func hr_eq(a: *u8, b: *u8, n: i64) -> i64 |
| 35 | func hr_lower(c: u8) -> u8 |
| 40 | func hr_ieq(a: *u8, b: *u8, n: i64) -> i64 |
| 47 | func hr_putdec(out: *u8, v: i64) -> i64 |
| 65 | func hr_req_path(req: *u8, reqn: i64, out: *u8, cap: i64) -> i64 |
| 84 | func hr_req_query(req: *u8, reqn: i64, out: *u8, cap: i64) -> i64 |
| 110 | func hr_req_host(req: *u8, reqn: i64, out: *u8, cap: i64) -> i64 |
| 136 | func hr_lookup_root(cfg: *u8, cfgn: i64, host: *u8, hostn: i64, out: *u8, cap: i64) -> i64 |
| 170 | func hr_path_safe(path: *u8, pathn: i64) -> i64 |
| 183 | func hr_resolve(root: *u8, rootn: i64, path: *u8, pathn: i64, out: *u8, cap: i64) -> i64 |
| 219 | func hr_ctype(file: *u8, filen: i64) -> *u8 |
| 258 | func hr_emit(out: *u8, statusline: *u8, ctype: *u8, body: *u8, bodyn: i64) -> i64 |
| 277 | func hr_known_host(cfg: *u8, cfgn: i64, req: *u8, reqn: i64) -> i64 |
| 288 | func hr_serve(cfg: *u8, cfgn: i64, req: *u8, reqn: i64, out: *u8, outcap: i64) -> i64 |
| 336 | func hr_ae_lc(c: i64) -> i64 { if c >= 65 { if c <= 90 { return c + 32 } } return c } called by 1: hr_accepts_gzip |
| 337 | func hr_accepts_gzip(req: *u8, reqn: i64) -> i64 |
| 360 | func hr_emit_b(out: *u8, outcap: i64, statusline: *u8, ctype: *u8, body: *u8, bodyn: i64) -> i64 called by 6: hr_serve3_slothr_serve3sd2_circle_uploadsd2_circle_listsd2_circle_playmain calls 1: hr_emit_bz |
| 364 | func hr_emit_bz(out: *u8, outcap: i64, statusline: *u8, ctype: *u8, body: *u8, bodyn: i64, gz: i64) -> i64 |
| 457 | func hr_serve2(cfg: *u8, cfgn: i64, req: *u8, reqn: i64, out: *u8, outcap: i64, out_n: *i64) -> i64 |
| 490 | func hr_emit_404(out: *u8, outcap: i64) -> i64 |
| 515 | func hr_stream_body() -> i64 { return hr_stream_p } |
| 516 | func hr_stream_bodyn() -> i64 { return hr_stream_n } |
| 520 | func hr_decimal_len(v: i64) -> i64 { var x: i64=v;var n: i64=1;while x>=10 { n=n+1;x=x/10 };return n } |
| 521 | func hr_emit_head(out: *u8, outcap: i64, statusline: *u8, ctype: *u8, bodyn: i64) -> i64 |
| 560 | func hr_ends2(s: *u8, n: i64, suf: *u8, sufn: i64) -> i64 |
| 569 | func hr_canon(path: *u8, pn: i64, loc: *u8) -> i64 |
| 589 | func hr_join(root: *u8, rn: i64, path: *u8, pn: i64, suffix: *u8, file: *u8, cap: i64) -> i64 |
| 606 | func hr_resolve_read(root: *u8, rn: i64, path: *u8, pn: i64, file: *u8, cap: i64, fnlen: *i64, dn: *i64) -> *u8 |
| 632 | func hr_emit_redirect(out: *u8, outcap: i64, loc: *u8, locn: i64) -> i64 |
| 649 | func hr_ct_is_html(ct: *u8) -> i64 |
| 654 | func hr_find_close_body(body: *u8, bn: i64) -> i64 |
| 667 | func hr_has_optout(body: *u8, bn: i64) -> i64 |
| 691 | func hr_find_slot_anchor(d: *u8, n: i64) -> i64 |
| 703 | func hr_serve3_slot(cfg: *u8, cfgn: i64, req: *u8, reqn: i64, out: *u8, outcap: i64, out_n: *i64, slot: *u8, slot_n: i64, injected: *i64) -> i64 |
| 798 | func hr_serve3(cfg: *u8, cfgn: i64, req: *u8, reqn: i64, out: *u8, outcap: i64, out_n: *i64) -> i64 |
| 853 | func hr_take_file_reader() -> *NxFileReadRegion |
| 857 | func hr_field(req: *u8,n: i64,name: *u8,len: *i64) -> i64 |
| 877 | func hr_emit_range_head(out: *u8,cap: i64,ct: *u8,r: *NxFileReadRegion,unsat: i64) -> i64 |
| 900 | func hr_try_file_range(root: *u8,rn: i64,path: *u8,pn: i64,req: *u8,reqn: i64,out: *u8,cap: i64,outn: *i64) -> i64 |