Net.HTTP.Syntax
The small grammars of RFC 9110 that header values are written in: tokens, quoted strings, parameters and comma-separated lists.
Every function works on bytes, not characters. The grammar is defined over octets, and each byte it gives a meaning to is ASCII, so a cut made next to one of those bytes is never inside a UTF-8 sequence.
A value is read once, whole, and is a few hundred bytes at most, so the
grammars are written as a cursor over the bytes with ? on Option rather
than with combinators: each rule is a few lines that read as the RFC's ABNF
does. URL shares the byte helpers.
field-vchar = VCHAR / obs-text. Bytes from 0x80 are obs-text, which the RFC
tells a recipient to treat as opaque; they arrive here only as parts of
UTF-8 sequences, since a String holds nothing else.
What a quoted string can carry, unescaped or after a backslash: HTAB, SP, VCHAR and obs-text. Every other control byte, CR, LF and NUL among them, has no spelling inside quotes.
Returns the offset of the first needle at or after from, or the length
of s if there is none, so that the result is always a place to cut.
field-value = *field-content, which neither starts nor ends with whitespace: SP and HTAB are allowed only between visible bytes.
Returns s as a quoted-string, with " and \ escaped. s must pass
canQuote; the callers check it before they build the value that is
written.
Returns s with ASCII letters lowercased and every other byte unchanged.
Returns bytes start up to stop of s. Both must be next to an ASCII
byte or at an end, which every cut the grammars make is.
A position in a value being read.
Returns the byte at the cursor, or -1 at the end.
OWS = *( SP / HTAB )
Consumes b if it is next.
token = 1*tchar
quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE, returned with its quotes removed and its escapes undone.
Returns the bytes from the cursor to the end, and moves it there.
Returns the elements of a comma-separated list (RFC 9110 ยง5.6.1), with the
whitespace around each removed. Commas inside a quoted string do not
separate. Empty elements are dropped, as a recipient must accept
a, , b as a, b. Returns None if a quoted string is not closed.
Returns s with every byte outside printable ASCII written as \xNN, for
a diagnostic that quotes text it refused: a refused value may hold the very
CR and LF that make it dangerous, and a message must not carry them on.