code wiki / (root) / nx_http_cache.nx

nx_http_cache.nx

buildroot/runtime/nx_http_cache.nx

11306 B327 linesdepth 1pulls 1 transitivereach 3 importersview sourcekind librarytopic http
docsdependenciesstructsconstsfunctions

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

nx_http_header_find.nx nx_http_cache.nx nx_audit_server_routed.nx nx_cms_cache_exceed_gate.nx nx_http_cache_test.nx

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

37const NXC_MAGIC_3750763034362895579: i64 = 3750763034362895579
38const NXC_MAGIC_1099511628211: i64 = 1099511628211
42const NXC_OK_FRESH: i64 = 0 // serve fresh; emit ETag
43const NXC_OK_NOT_MODIFIED: i64 = 1 // emit 304; skip body
44const NXC_OOM_BUFFER: i64 = 2
45const NXC_BAD_ARG: i64 = 3
46const NXC_VERDICT_N: i64 = 4

functions

48func nxc_verdict_is_valid(v: i64) -> i64
called by 1: main
54func nxc_verdict_name(v: i64) -> *u8
called by 1: main
75func nxc_fnv1a_64(bytes: *u8, n: i64) -> i64
93func nxc_put_hex_64(out: *u8, off: *i64, cap: i64, v: i64) -> i64
116func nx_http_etag_compute(body: *u8, body_n: i64,
140func nx_http_if_none_match_matches(
180func nxc_put(out: *u8, off: *i64, cap: i64, b: i64) -> i64
187func nxc_put_cstr(out: *u8, off: *i64, cap: i64, s: *u8) -> i64
197func nxc_put_bytes(out: *u8, off: *i64, cap: i64, src: *u8, n: i64) -> i64
called by 1: nx_http_emit_304 calls 1: nxc_put
207func nx_http_emit_304(out: *u8, off: *i64, cap: i64,
266func nx_http_emit_cache_control_header(
314func nx_http_cache_decide(