http.etag.weakEqual
v0.1.0 latestWeak ETag comparison: compares opaque-tag values ignoring the weak/strong flag per RFC 9110 §8.8.3.2.
Weak ETag comparison: compares opaque-tag values ignoring the weak/strong flag per RFC 9110 §8.8.3.2.
Signature
function weakEqual(a: ETag, b: ETag): boolean
Type Definitions:
ETag— interface
Problem
RFC 9110 defines two ETag comparison functions with different semantics. Weak comparison ignores the W/ flag and is used for If-None-Match (304 Not Modified). Implementing the wrong comparison function leads to incorrect cache behavior.
How It Works
Compares a.value === b.value, ignoring the weak flag on both operands.
Boundaries
- Ignores the weak flag — W/"abc" equals "abc".
- For strong comparison (If-Match), use strongEqual instead.
Replaces
Common boilerplate this function replaces:
a.value === b.value
Examples
http.etag.weakEqual({ weak: true, value: "a" }, { weak: false, value: "a" }); // true
http.etag.weakEqual({ weak: true, value: "a" }, { weak: true, value: "b" }); // false
Standards
Caveats
- Use weakEqual for If-None-Match (304 Not Modified) scenarios.
- Use strongEqual for If-Match scenarios where byte-level identity is required.
FAQ
What is weak ETag comparison?
Weak comparison ignores the W/ flag and compares only the opaque-tag values. Used for If-None-Match / 304 Not Modified.
When should I use weak vs strong ETag comparison?
Use weakEqual for If-None-Match (caching). Use strongEqual for If-Match (range requests, conditional writes).
Does weakEqual care about the W/ prefix?
No. weakEqual({ weak: true, value: 'a' }, { weak: false, value: 'a' }) returns true.
Is weakEqual the correct comparison for 304 Not Modified?
Yes. RFC 9110 §13.1.2 specifies weak comparison for If-None-Match evaluation.
What is the difference between weakEqual and strongEqual?
weakEqual ignores the W/ flag. strongEqual requires both ETags to be strong (weak: false) and have matching values.