http.etag.parseIfNoneMatch
v0.1.0 latestParse an If-None-Match header value into a structured IfNoneMatch object per RFC 9110 §13.1.2.
Parse an If-None-Match header value into a structured IfNoneMatch object per RFC 9110 §13.1.2.
Signature
function parseIfNoneMatch(header: string): IfNoneMatch | null
Type Definitions:
IfNoneMatch— type
Problem
If-None-Match headers can contain *, single ETags, or comma-separated lists. Parsing must handle all three forms and reject invalid combinations (e.g. * mixed with other tags).
How It Works
Handles * (any), single ETags, and comma-separated lists. * mixed with other tags returns null (invalid per RFC 9110).
Boundaries
- Returns null for empty input, any parse failure, or invalid combinations.
- Throws TypeError for non-string input.
-
- mixed with other tags returns null.
Replaces
Common boilerplate this function replaces:
header === '*' ? { any: true } : { tags: header.split(',').map(s => parseETag(s.trim())).filter(Boolean) }
Examples
http.etag.parseIfNoneMatch("*"); // { any: true }
http.etag.parseIfNoneMatch('"a", W/"b"'); // { tags: [{ weak: false, value: "a" }, { weak: true, value: "b" }] }
http.etag.parseIfNoneMatch('*, "a"'); // null
Standards
Caveats
- If any individual ETag in the list fails to parse, the entire result is null.
-
- must appear alone — mixing * with other tags is invalid per RFC 9110.
FAQ
How to parse an If-None-Match header?
http.etag.parseIfNoneMatch('"a", W/"b"') returns { tags: [...] }. Handles *, single, and multi-tag formats.
What does * mean in If-None-Match?
- matches any current ETag. parseIfNoneMatch('*') returns { any: true }.
Can * be mixed with other ETags?
No. '*, "a"' is invalid per RFC 9110 and returns null.
What happens if one ETag in the list is malformed?
The entire parse returns null. All entries must be valid.
How to implement 304 Not Modified with this?
Parse the If-None-Match header, then use matchesIfNoneMatch() to check against the current ETag.