Skip to content

Commit 8ca6148

Browse files
mikewestannevk
authored andcommitted
"Get" a structured header value from a header list
As discussed in #930 and WICG/cross-origin-embedder-policy#2, this adds a "get" algorithm on header lists that allows consistent extraction of structured header values.
1 parent 9753176 commit 8ca6148

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

fetch.bs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ url:https://tools.ietf.org/html/rfc7230#section-3.1.2;text:reason-phrase;type:df
1818
url:https://tools.ietf.org/html/rfc7234#section-1.2.1;text:delta-seconds;type:dfn;spec:http-caching
1919
url:https://tools.ietf.org/html/draft-ietf-httpbis-header-structure#section-2;text:structured header value;type:dfn;spec:header-structure
2020
url:https://tools.ietf.org/html/draft-ietf-httpbis-header-structure#section-4.1;text:serializing structured headers;type:dfn;spec:header-structure
21+
url:https://tools.ietf.org/html/draft-ietf-httpbis-header-structure#section-4.2;text:parsing structured headers;type:dfn;spec:header-structure
2122
</pre>
2223

2324
<pre class=biblio>
@@ -380,6 +381,50 @@ for consistency.
380381
<p class="note no-backref">A <a for=/>header list</a> is essentially a
381382
specialized multimap. An ordered list of key-value pairs with potentially duplicate keys.
382383

384+
<p>To
385+
<dfn export for="header list" id=concept-header-list-get-structured-header>get a structured header</dfn>
386+
given a <var>name</var> and a <var>type</var> from a <a for=/>header list</a> <var>list</var>, run
387+
these steps:
388+
389+
<ol>
390+
<li><p>Assert: <var>type</var> is one of "<code>dictionary</code>", "<code>list</code>", or
391+
"<code>item</code>".
392+
393+
<li><p>Let <var>value</var> be the result of <a for="header list">getting</a> <var>name</var> from
394+
<var>list</var>.
395+
396+
<li><p>If <var>value</var> is null, then return null.
397+
398+
<li><p>Let <var>result</var> be the result of executing the <a>parsing structured headers</a>
399+
algorithm with <var ignore>input_string</var> set to <var>value</var>, and
400+
<var ignore>header_type</var> set to <var>type</var>.
401+
402+
<li><p>If parsing failed, then return failure.
403+
404+
<li><p>Return <var>result</var>.
405+
</ol>
406+
407+
<p>To
408+
<dfn export for="header list" id=concept-header-list-set-structured-header>set a structured header</dfn>
409+
<a for=header>name</a>/<a>structured header value</a> <var>name</var>/<var>structuredValue</var>
410+
pair in a <a for=/>header list</a> <var>list</var>, run these steps:
411+
412+
<ol>
413+
<li><p>Let <var>serializedValue</var> be the result of executing the
414+
<a>serializing structured headers</a> algorithm on <var>structuredValue</var>.
415+
416+
<li><p><a for="header list">Set</a> <var>name</var>/<var>serializedValue</var> in <var>list</var>.
417+
</ol>
418+
419+
<p class=note><a>Structured header values</a> are defined as objects which HTTP can (eventually)
420+
serialize in interesting and efficient ways. For the moment, Fetch only supports <a for=/>header</a>
421+
<a for=header>values</a> as <a for=/>byte sequences</a>, which means that these objects can be set
422+
in <a for=/>header lists</a> only via serialization, and they can be obtained from
423+
<a for=/>header lists</a> only by parsing. In the future the fact that they are objects might be
424+
preserved end-to-end. [[!HEADER-STRUCTURE]]
425+
426+
<hr>
427+
383428
<p>A <a for=/>header list</a> <var>list</var>
384429
<dfn export for="header list" lt="contains|does not contain">contains</dfn> a <a for=header>name</a>
385430
<var>name</var> if <var>list</var> <a for=list>contains</a> a <a for=/>header</a> whose
@@ -572,23 +617,6 @@ A: 3
572617
<var>name</var> and <a for=header>value</a> is <var>value</var> to <var>list</var>.
573618
</ol>
574619

575-
<p>To
576-
<dfn export for="header list" id=concept-header-list-set-structured-header>set a structured header</dfn>
577-
<a for=header>name</a>/<a>structured header value</a> <var>name</var>/<var>structuredValue</var>
578-
pair in a <a for=/>header list</a> <var>list</var>, run these steps:
579-
580-
<ol>
581-
<li><p>Let <var>serializedValue</var> be the result of executing the
582-
<a>serializing structured headers</a> algorithm on <var>structuredValue</var>.
583-
584-
<li><p><a for="header list">Set</a> <var>name</var>/<var>serializedValue</var> in <var>list</var>.
585-
</ol>
586-
587-
<p class="note"><a>Structured header values</a> are defined as objects which HTTP can (eventually)
588-
serialize in interesting and efficient ways. For the moment, Fetch only supports setting these
589-
objects in <a for=/>header lists</a> by serializing them. In the future the fact that they are
590-
objects might be preserved end-to-end. [[!HEADER-STRUCTURE]]
591-
592620
<p>To <dfn export for="header list" id=concept-header-list-combine>combine</dfn> a
593621
<a for=header>name</a>/<a for=header>value</a> <var>name</var>/<var>value</var> pair in a
594622
<a for=/>header list</a> <var>list</var>, run these steps:

0 commit comments

Comments
 (0)