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-Controlheaderinto a directive map. -
parseETag(
String header) → ({String value, bool weak})? -
Parses an
ETagheaderinto its weakness flag and unquoted tag value. -
parseMaxAge(
String cacheControl) → int? -
Returns the
max-ageseconds from aCache-ControlcacheControlstring, ornullif 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-Afterheaderinto a Duration, ornullwhen it is not a non-negative integer.