http.etag.strongEqual
v0.1.0 latestStrong ETag comparison: both must be strong (weak === false) and values must match per RFC 9110 §8.8.3.2.
Strong ETag comparison: both must be strong (weak === false) and values must match per RFC 9110 §8.8.3.2.
Signature
function strongEqual(a: ETag, b: ETag): boolean
Type Definitions:
ETag— interface
Problem
Strong comparison is required for If-Match headers (conditional PUT, range requests) where byte-level identity matters. Using weak comparison in these scenarios leads to data corruption.
How It Works
Returns true only when both ETags are strong (weak === false) and their values match.
Boundaries
- Returns false if either ETag is weak, even if values match.
- For If-None-Match scenarios, use weakEqual instead.
Replaces
Common boilerplate this function replaces:
!a.weak && !b.weak && a.value === b.value
Examples
http.etag.strongEqual({ weak: false, value: "a" }, { weak: false, value: "a" }); // true
http.etag.strongEqual({ weak: true, value: "a" }, { weak: false, value: "a" }); // false
Standards
Caveats
- Use strongEqual for If-Match and range request scenarios only.
- Weak ETags always fail strong comparison, even when values match.
FAQ
What is strong ETag comparison?
Strong comparison requires both ETags to be strong (not weak) and have matching values. Used for If-Match headers.
When should I use strong ETag comparison?
For If-Match conditional requests (PUT, PATCH, DELETE) and range requests where byte-level identity is required.
Why does a weak ETag fail strong comparison?
Weak ETags indicate semantic equivalence, not byte-level identity. Strong comparison requires byte-level identity per RFC 9110.
Can a weak and strong ETag with the same value be strongly equal?
No. strongEqual({ weak: true, value: 'a' }, { weak: false, value: 'a' }) returns false.
What is the difference between If-Match and If-None-Match comparison?
If-Match uses strong comparison (strongEqual). If-None-Match uses weak comparison (weakEqual). Different cache semantics.