Skip to main content

Module conditional

Module conditional 

Source
Expand description

ETags and conditional requests

  • ETags middleware: tags GET responses with an ETag derived from the body and answers 304 Not Modified when the client’s If-None-Match still matches. Responses that already carry an ETag keep it.
  • require_if_match: optimistic concurrency for updates. The client sends the ETag it last saw as If-Match; a stale one gets 412, a missing one 428, so concurrent edits cannot silently overwrite each other.
use ullun::conditional::{etag_for, if_none_match_hits};

let tag = etag_for(b"hello");
assert!(if_none_match_hits(&tag, &tag));
assert!(if_none_match_hits("\"other\", *", &tag));
assert!(!if_none_match_hits("\"other\"", &tag));

Structs§

ETags
Middleware adding ETag and 304 Not Modified handling to GET responses

Functions§

etag_for
Strong ETag for a body: 64-bit FNV-1a plus the length, e.g. "2f3c...-5". Stable across processes and releases (unlike DefaultHasher).
if_match_hits
If-Match evaluation: strong comparison, so weak tags never match
if_none_match_hits
If-None-Match evaluation: weak comparison, * matches anything
require_if_match
Precondition for updating a resource whose current tag is current_etag