Expand description
Header helpers used by axum-bound handlers: optimistic-locking ETag
parsing/emission, W3C traceparent extraction, RFC 7239 Forwarded
client-IP extraction, and context enrichment that bundles those.
Functions§
- enrich_
context_ from_ headers - Enrich a
CoolContextwith the request id (fromtraceparent) and the client IP (fromForwarded/X-Forwarded-For). Malformedtraceparentheaders are silently ignored here — the auth/header-validation layer is the right place to reject them, not the enrichment seam. - parse_
client_ ip - Extract the most-specific client IP available from the request headers,
falling back to none. Prefers
Forwarded(RFC 7239) over the legacyX-Forwarded-For. Banks running behind a single trusted L7 take the leftmost entry; deeper proxy chains must verify and rewrite at the edge. - parse_
if_ match_ version - Parse an
If-Matchheader carrying a strong ETag of the form"<int>". ReturnsNoneif the header is absent. Returns an error if the header is present but malformed (weak validators, non-integer payloads, etc.). - parse_
traceparent - Extract a W3C
traceparentheader, returning the trace-id portion when the header is present and well-formed. ReturnsOk(None)when absent — callers should mint their own request id in that case so every audit row carries something. The trace-id is the second hyphen-delimited segment per W3C Trace Context; this implementation does not validate the flags/version segments since banks usually rebuild traceparent at the edge anyway. - set_
version_ etag - Insert an
ETagheader onto a response, formatted as a strong validator over the integer optimistic-locking version.