nx_http_cache.nx
buildroot/runtime/nx_http_cache.nx
about
nx_http_cache.nx -- HTTP caching primitives (ETag + 304).
Standard nginx/apache behavior: substrate emits ETag header on
every cacheable response; client sends back If-None-Match on the
next request; substrate compares + emits 304 Not Modified if
content unchanged.
Saves bandwidth on repeated dashboard loads: a 14 KB response
becomes a 113-byte 304 header.
Per cardinal feedback-no-third-party-trust-native-or-nothing:
substrate's own ETag computation. No external hash library.
ETag algorithm: FNV-1a 64-bit hash of response body bytes
emitted as 16-char lowercase hex. Weak-equivalent per RFC 7232
ยง2.1 (the weak prefix `W/` is not emitted; substrate uses strong
equivalence -- byte-equal response = byte-equal ETag).
FNV-1a was chosen because:
1. No crypto-dep transitive imports (works under any syscall ABI)
2. ~1 GB/s single-thread on modern hardware (no perf hit)
3. Adequate collision resistance for HTTP caching (not security)
4. ~30 LOC; auditable
nx_capability_claims:
needs: [sealed_enum, byte_ops, http_header_search]
provides: [etag_compute_fnv1a_hex, cache_control_emit,
304_not_modified_emit, if_none_match_parse]
safety: [no_unchecked_deref, no_floating_point, no_syscall,
bounded_iteration, bit_equal_reproducible]
verdict: [sealed_enum_4_state]
license: ORIGINAL
kind: racing_crew_specialist
layer: L3 (algorithm: HTTP cache decision)
dependencies 1 imports · 3 importers
imports: nx_http_header_find.nx
imported by: nx_audit_server_routed.nxnx_cms_cache_exceed_gate.nxnx_http_cache_test.nx
structs
| none |
consts
| 37 | const NXC_MAGIC_3750763034362895579: i64 = 3750763034362895579 |
| 38 | const NXC_MAGIC_1099511628211: i64 = 1099511628211 |
| 42 | const NXC_OK_FRESH: i64 = 0 // serve fresh; emit ETag |
| 43 | const NXC_OK_NOT_MODIFIED: i64 = 1 // emit 304; skip body |
| 44 | const NXC_OOM_BUFFER: i64 = 2 |
| 45 | const NXC_BAD_ARG: i64 = 3 |
| 46 | const NXC_VERDICT_N: i64 = 4 |
functions
| 48 | func nxc_verdict_is_valid(v: i64) -> i64 called by 1: main |
| 54 | func nxc_verdict_name(v: i64) -> *u8 called by 1: main |
| 75 | func nxc_fnv1a_64(bytes: *u8, n: i64) -> i64 |
| 93 | func nxc_put_hex_64(out: *u8, off: *i64, cap: i64, v: i64) -> i64 |
| 116 | func nx_http_etag_compute(body: *u8, body_n: i64, |
| 140 | func nx_http_if_none_match_matches( |
| 180 | func nxc_put(out: *u8, off: *i64, cap: i64, b: i64) -> i64 |
| 187 | func nxc_put_cstr(out: *u8, off: *i64, cap: i64, s: *u8) -> i64 |
| 197 | func nxc_put_bytes(out: *u8, off: *i64, cap: i64, src: *u8, n: i64) -> i64 |
| 207 | func nx_http_emit_304(out: *u8, off: *i64, cap: i64, |
| 266 | func nx_http_emit_cache_control_header( |
| 314 | func nx_http_cache_decide( |