nx_etag.nx
buildroot/runtime/nx_etag.nx
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
imports: nx_syscalls.nxnx_sha256.nxnx_hex_codec.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 43 | const ETAG_ERR_SHORT: i64 = -1 |
functions
| 49 | func etag_gen_strong(data: *u8, n: i64, |
| 72 | func etag_gen_weak(data: *u8, n: i64, |
| 83 | func etag_is_weak(tag: *u8, n: i64) -> i64 |
| 93 | func etag_strip_quotes(tag: *u8, n: i64, |
| 107 | func etag_weak_match(a: *u8, a_len: i64, |
| 127 | func etag_strong_match(a: *u8, a_len: i64, |
| 135 | func main() -> i64 |