Skip to content

Commit

Permalink
"Get" a structured header value from a header list
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mikewest authored and annevk committed Dec 28, 2019
1 parent 9753176 commit 8ca6148
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ url:https://tools.ietf.org/html/rfc7230#section-3.1.2;text:reason-phrase;type:df
url:https://tools.ietf.org/html/rfc7234#section-1.2.1;text:delta-seconds;type:dfn;spec:http-caching
url:https://tools.ietf.org/html/draft-ietf-httpbis-header-structure#section-2;text:structured header value;type:dfn;spec:header-structure
url:https://tools.ietf.org/html/draft-ietf-httpbis-header-structure#section-4.1;text:serializing structured headers;type:dfn;spec:header-structure
url:https://tools.ietf.org/html/draft-ietf-httpbis-header-structure#section-4.2;text:parsing structured headers;type:dfn;spec:header-structure
</pre>

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

<p>To
<dfn export for="header list" id=concept-header-list-get-structured-header>get a structured header</dfn>
given a <var>name</var> and a <var>type</var> from a <a for=/>header list</a> <var>list</var>, run
these steps:

<ol>
<li><p>Assert: <var>type</var> is one of "<code>dictionary</code>", "<code>list</code>", or
"<code>item</code>".

<li><p>Let <var>value</var> be the result of <a for="header list">getting</a> <var>name</var> from
<var>list</var>.

<li><p>If <var>value</var> is null, then return null.

<li><p>Let <var>result</var> be the result of executing the <a>parsing structured headers</a>
algorithm with <var ignore>input_string</var> set to <var>value</var>, and
<var ignore>header_type</var> set to <var>type</var>.

<li><p>If parsing failed, then return failure.

<li><p>Return <var>result</var>.
</ol>

<p>To
<dfn export for="header list" id=concept-header-list-set-structured-header>set a structured header</dfn>
<a for=header>name</a>/<a>structured header value</a> <var>name</var>/<var>structuredValue</var>
pair in a <a for=/>header list</a> <var>list</var>, run these steps:

<ol>
<li><p>Let <var>serializedValue</var> be the result of executing the
<a>serializing structured headers</a> algorithm on <var>structuredValue</var>.

<li><p><a for="header list">Set</a> <var>name</var>/<var>serializedValue</var> in <var>list</var>.
</ol>

<p class=note><a>Structured header values</a> are defined as objects which HTTP can (eventually)
serialize in interesting and efficient ways. For the moment, Fetch only supports <a for=/>header</a>
<a for=header>values</a> as <a for=/>byte sequences</a>, which means that these objects can be set
in <a for=/>header lists</a> only via serialization, and they can be obtained from
<a for=/>header lists</a> only by parsing. In the future the fact that they are objects might be
preserved end-to-end. [[!HEADER-STRUCTURE]]

<hr>

<p>A <a for=/>header list</a> <var>list</var>
<dfn export for="header list" lt="contains|does not contain">contains</dfn> a <a for=header>name</a>
<var>name</var> if <var>list</var> <a for=list>contains</a> a <a for=/>header</a> whose
Expand Down Expand Up @@ -572,23 +617,6 @@ A: 3
<var>name</var> and <a for=header>value</a> is <var>value</var> to <var>list</var>.
</ol>

<p>To
<dfn export for="header list" id=concept-header-list-set-structured-header>set a structured header</dfn>
<a for=header>name</a>/<a>structured header value</a> <var>name</var>/<var>structuredValue</var>
pair in a <a for=/>header list</a> <var>list</var>, run these steps:

<ol>
<li><p>Let <var>serializedValue</var> be the result of executing the
<a>serializing structured headers</a> algorithm on <var>structuredValue</var>.

<li><p><a for="header list">Set</a> <var>name</var>/<var>serializedValue</var> in <var>list</var>.
</ol>

<p class="note"><a>Structured header values</a> are defined as objects which HTTP can (eventually)
serialize in interesting and efficient ways. For the moment, Fetch only supports setting these
objects in <a for=/>header lists</a> by serializing them. In the future the fact that they are
objects might be preserved end-to-end. [[!HEADER-STRUCTURE]]

<p>To <dfn export for="header list" id=concept-header-list-combine>combine</dfn> a
<a for=header>name</a>/<a for=header>value</a> <var>name</var>/<var>value</var> pair in a
<a for=/>header list</a> <var>list</var>, run these steps:
Expand Down

0 comments on commit 8ca6148

Please sign in to comment.