code wiki / (root) / etag.nx

etag.nx

buildroot/runtime/etag.nx

5666 B155 linesdepth 6pulls 7 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

etag.nx -- generate + compare HTTP ETag headers (RFC 7232). The ETag header identifies a specific version of a resource so conditional requests (If-None-Match / If-Match) can avoid re-sending bytes that haven't changed. Every static-file server needs this, every CDN lives or dies on it. Format (RFC 7232 §2.3): ETag: "33a64df551425fcc55e4d42a148795d9f25f89d4" <- strong ETag: W/"3ad4a9c3" <- weak Strong ETags mean byte-exact match; weak (W/-prefixed) means semantically equivalent but possibly byte-different (e.g. same content reflowed whitespace). We generate ETags by: 1. sha256 (existing) of the file contents -> 32 bytes 2. hex-encode (existing) -> 64 ASCII chars 3. truncate to etag_size bytes (caller choice; 8-32 typical) 4. wrap in double quotes Comparison follows RFC 7232 §2.3.2: strong match requires both to be strong and byte-identical; weak match matches regardless of W/- prefix. Invariants: ET1 Output always ends with a trailing DQUOTE. ET2 Weak prefix is exactly "W/" (2 ASCII bytes, case-sensitive). ET3 Caller chooses truncation length; 8 hex chars (4 bytes of entropy) is the minimum practical, 32 (128 bits) is plenty.

dependencies 3 imports · 0 importers

syscalls.nx sha256.nx hex.nx etag.nx

imports: syscalls.nxsha256.nxhex.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main etag_gen_strong hex_encode etag_gen_weak etag_gen_strong ↻ etag_weak_match etag_strip_quotes etag_is_weak etag_strong_match etag_is_weak ↻ etag_weak_match ↻

structs

none

consts

37const ETAG_ERR_SHORT: i64 = -1

functions

43func etag_gen_strong(data: *u8, n: i64,
called by 2: etag_gen_weakmain calls 1: hex_encode
66func etag_gen_weak(data: *u8, n: i64,
called by 1: main calls 1: etag_gen_strong
77func etag_is_weak(tag: *u8, n: i64) -> i64 {
87func etag_strip_quotes(tag: *u8, n: i64,
called by 1: etag_weak_match calls 1: etag_is_weak
101func etag_weak_match(a: *u8, a_len: i64,
121func etag_strong_match(a: *u8, a_len: i64,
called by 1: main calls 2: etag_is_weaketag_weak_match
129func main() -> i64 {