A typed grammar for HTTP headers
Historically every HTTP header invented its own ad-hoc syntax, making parsers fragile. RFC 8941 Structured Field Values defines a small, typed grammar so new headers can be parsed uniformly. This reference explains the three top-level types, the bare-item types and parameter syntax, with a live parser that classifies any value you paste.
How it works
A header’s spec declares it as one of three top-level types:
Item: Content-Length: 42
List: Accept-Encoding: gzip, br;q=0.8, *;q=0.1
Dictionary: Cache-Status: ExampleCache; hit, ExampleCache2; fwd=uri-miss
Each member is a bare item of a fixed type — Integer, Decimal, String
(double-quoted), Token (unquoted), Byte Sequence (:base64:) or Boolean
(?1/?0) — optionally carrying ;key=value parameters. An inner list
wraps several items in parentheses as one member. The parser below detects the
top-level type heuristically (a top-level = outside quotes implies a
Dictionary; a comma implies a List; otherwise an Item) and reports each member.
Tips and notes
- Strings are double-quoted and may only contain printable ASCII; Tokens are unquoted.
- A bare parameter key (
;sni) is shorthand for;sni=?1(Boolean true). - Byte sequences are base64 wrapped in colons:
:cHF=:. - Decimals have at most three fractional digits; larger precision needs a String.
- Use Structured Fields for new headers so generic libraries can parse them safely.