parsing/http_header_parse_utils library

Parse common HTTP caching headers without any HTTP dependency — roadmap #632.

Pure string parsing for the directives a client most often inspects: Cache-Control (and its max-age), ETag (strong vs weak), and the numeric form of Retry-After. No dart:io/package:http types are used, so these helpers run on every platform including web. Malformed input yields null rather than throwing, so callers can fall back to a default.

Functions

parseCacheControl(String header) Map<String, String?>
Parses a Cache-Control header into a directive map.
parseETag(String header) → ({String value, bool weak})?
Parses an ETag header into its weakness flag and unquoted tag value.
parseMaxAge(String cacheControl) int?
Returns the max-age seconds from a Cache-Control cacheControl string, or null if the directive is absent or its value is not a non-negative int. Audited: 2026-06-12 11:26 EDT
parseRetryAfterSeconds(String header) Duration?
Parses the numeric (delta-seconds) form of a Retry-After header into a Duration, or null when it is not a non-negative integer.