Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add special handling of set-cookie to Headers #1346

Merged
merged 16 commits into from
Feb 8, 2023
59 changes: 49 additions & 10 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,30 @@ a <a for=/>header list</a> <var>list</var>, run these steps:
<p><a for=list>For each</a> <var>name</var> in <var>names</var>:

<ol>
<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>name</var> is `<code>set-cookie</code>`, then:
andreubotella marked this conversation as resolved.
Show resolved Hide resolved

<ol>
<li><p>Let <var>values</var> be a list of all <a lt=value for=header>values</a> of
<a for=/>headers</a> in <var>list</var> whose <a for=header>name</a> is a
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved
<a>byte-case-insensitive</a> match for <var>name</var>, in order.

<li><p><a for=list>For each</a> <var>value</var> of <var>values</var>:
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved

<ol>
<li><p><a for=list>Append</a> (<var>name</var>, <var>value</var>) to <var>headers</var>.
</ol>
</ol>

<li><p>Otherwise:

<ol>
<li><p>Let <var>value</var> be the result of <a for="header list">getting</a> <var>name</var>
andreubotella marked this conversation as resolved.
Show resolved Hide resolved
from <var>list</var>.

<li><p>Assert: <var>value</var> is not null.
<li><p>Assert: <var>value</var> is not null.

<li><p><a for=list>Append</a> (<var>name</var>, <var>value</var>) to <var>headers</var>.
<li><p><a for=list>Append</a> (<var>name</var>, <var>value</var>) to <var>headers</var>.
</ol>
</ol>

<li><p>Return <var>headers</var>.
Expand Down Expand Up @@ -5960,18 +5978,25 @@ interface Headers {
undefined append(ByteString name, ByteString value);
undefined delete(ByteString name);
ByteString? get(ByteString name);
sequence&lt;ByteString> getSetCookie();
boolean has(ByteString name);
undefined set(ByteString name, ByteString value);
iterable&lt;ByteString, ByteString>;
};
</pre>

<p class=note>Unlike a <a for=/>header list</a>, a {{Headers}} object cannot represent more than one
`<code>Set-Cookie</code>` <a for=/>header</a>. In a way this is problematic as unlike all other
headers `<code>Set-Cookie</code>` headers cannot be combined, but since `<code>Set-Cookie</code>`
headers are not exposed to client-side JavaScript this is deemed an acceptable compromise.
Implementations could choose the more efficient {{Headers}} object representation even for a
<a for=/>header list</a>, as long as they also support an associated data structure for
<p class=note>Unlike a <a for=/>header list</a>, a {{Headers}} object combines the values of
multiple headers of the same name into a single header value. This is problematic for the
`<code>Set-Cookie</code>` header, as unlike all other headers, it cannot be safely combined. Because
of this, there is some special handling for the `<code>Set-Cookie</code>` header in
the implementation of the {{Headers}} interface, just like in the HTTP spec.
`<code>Set-Cookie</code>` headers are not concatenated when they are returned from the {{Headers}}
iterator, and there is a
<code><var>headers</var> . <a method for=Headers lt=getSetCookie()>getSetCookie</a>()</code> method
to retrieve the list of all `<code>Set-Cookie</code>`, ordered and uncombined. This means that
specifically for this header, multiple tuples of the same name can be returned from the {{Headers}}
iterator. Implementations could choose the more efficient {{Headers}} object representation even for
a <a for=/>header list</a>, as long as they also support an associated data structure for
annevk marked this conversation as resolved.
Show resolved Hide resolved
`<code>Set-Cookie</code>` headers.
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved

<p>A {{Headers}} object has an associated
Expand Down Expand Up @@ -6018,6 +6043,9 @@ new Headers(meta2);
<dd><p>Returns as a string the values of all headers whose name is <var>name</var>, separated by a
comma and a space.

<dt><code><var>headers</var> . <a method for=Headers lt=getSetCookie()>getSetCookie</a>()</code>
<dd><p>Returns a list of the values for all headers whose name is `<code>Set-Cookie</code>`.

<dt><code><var>headers</var> . <a method for=Headers lt=has()>has</a>(<var>name</var>)</code>
<dd><p>Returns whether there is a header whose name is <var>name</var>.

Expand Down Expand Up @@ -6160,6 +6188,17 @@ method steps are to <a for=Headers>append</a> (<var>name</var>, <var>value</var>
<a for=Headers>header list</a>.
</ol>

<p>The <dfn export for=Headers method><code>getSetCookie()</code></dfn> method steps are:

<ol>
<li><p>If <a>this</a>'s <a for=Headers>header list</a> <a for="header list">does not contain</a> `<code>Set-Cookie</code>`, then
annevk marked this conversation as resolved.
Show resolved Hide resolved
return an empty list.
andreubotella marked this conversation as resolved.
Show resolved Hide resolved

<li><p>Return the <a lt=value for=header>values</a> of all <a for=/>headers</a> in <a>this</a>'s
<a for=Headers>header list</a> whose <a for=header>name</a> is a <a>byte-case-insensitive</a> match
for `<code>Set-Cookie</code>`, in order.
</ol>
lucacasonato marked this conversation as resolved.
Show resolved Hide resolved

<p>The <dfn export for=Headers method><code>has(<var>name</var>)</code></dfn> method steps are:

<ol>
Expand Down