Add getStructured/setStructured to Headers - #1943
Conversation
Adds new APIs to the Headers class for getting/setting structured header fields.
|
@jasnell are you building up towards RFC 9421: HTTP Message Signatures support? I'd be happy to help. |
|
@panva ... That's definitely one of the items on the agenda, yes. |
|
Would it be useful to have a spec of a canonical mapping of SF to JSON? |
|
... like the one used in the test suite? |
I would think so, yes |
|
Any reason why this needs to be baked in into |
|
"Something based on strings" is just what Headers already provides. Using an additional parser/serializer is obviously possible but adds an additional dependency which is what this is aiming to eliminate. |
|
What is the thinking about this sort of thing? const cc = response.headers.getStructured("Cache-Control", "dictionary");Presumably, this just runs the string through the identified SF parser, which might work out fine (or not), caveat emptor and all that jazz. |
Yes. If it can be parsed as the specified type, then it will be. Otherwise null is returned. |
Yes. What I was trying to say is that the API does not necessarily have to be attached to the |
Hmm... you're not wrong but I think having it on |
Adds new APIs to the Headers class for getting/setting structured header fields.
Structured fields are defined in RFC 8941. Newer HTTP header definitions build on it. Fetch's handling of all header values as strings works but loses some of the utility. This commit adds new
getStructured/setStructuredAPIS toHeadersfor getting/setting header field values as structured fields. The existingget/set/append/etc are left untouched. Header iteration is left untouched. It remains possible to get all fields as strings.There are currently ~36 standard headers that use structured header fields:
Dictionary
PrioritySignatureSignature-InputAccept-SignatureContent-DigestRepr-DigestWant-Content-DigestContent-Digestwith algorithm preferencesWant-Repr-DigestRepr-Digestwith algorithm preferencesCDN-Cache-ControlUse-As-DictionaryList
Cache-Statushit,fwd,ttl, etc.)Proxy-StatusAccept-CHClient-Cert-ChainAccept-QueryCache-GroupsCache-Group-InvalidationItem
Client-CertCapsule-ProtocolDeprecationAvailable-DictionaryDictionary-IDConcealed-Auth-ExportCross-Origin-Embedder-PolicyCross-Origin-Embedder-Policy-Report-OnlyCross-Origin-Opener-PolicyCross-Origin-Opener-Policy-Report-OnlyOrigin-Agent-ClusterSec-Fetch-DestSec-Fetch-ModeSec-Fetch-SiteSec-Fetch-UserSec-Purposeprefetch(Token)Examples
Reading the
Priorityheader (Dictionary)Compared with strings:
Reading Cache-Status (List)
Reading Content-Digest (Dictionary with Byte Sequences)
Reading Sec-Purpose (Item)
Writing Priority (Dictionary — plain object form)
Writing Cache-Status (List with parameters)
Writing Content-Digest (Dictionary with Byte Sequence)
Graceful fallback when unsupported
Token vs String serialization
All input forms for dictionaries and parameters (HeadersInit pattern)
(See WHATWG Working Mode: Changes for more details.)
Preview | Diff