Skip to content

Commit

Permalink
Use controller for terminating
Browse files Browse the repository at this point in the history
  • Loading branch information
noamr committed Oct 14, 2021
1 parent fe28b66 commit da4db3d
Showing 1 changed file with 59 additions and 62 deletions.
121 changes: 59 additions & 62 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ lt="authentication entry">authentication entries</a> (for HTTP authentication).
<dt><dfn for="fetch params">cross-origin isolated capability</dfn> (default false)
<dd>A boolean.

<dt><dfn for="fetch params">terminated flag</dfn>
<dt><dfn for="fetch params">aborted flag</dfn>
<dd>A flag, initially unset.

<dt><dfn for="fetch params">timing info</dfn>
<dd>A <a for=/>fetch timing info</a>.
</dl>
Expand Down Expand Up @@ -254,6 +258,19 @@ given a <a for=/>fetch timing info</a> <var>timingInfo</var>, return a new
<var>storedTimingInfo</var>'s <a for="fetch timing info">decoded body size</a>.
</ol>

<p>A <dfn export>fetch controller</dfn> is an object used to enable clients of an ongoing fetch
to perform certain actions in the context of that fetch instance.

<p>A <a for=/>fetch controller</a> has an associated <a for=/>fetch params</a>
<dfn for="fetch controller">ongoing fetch params</dfn>.</p>

<p>To <dfn for="fetch controller">terminate</dfn> a <a for=/>fetch controller</a>
<var>controller</var> given a flag <var>aborted</var>, which is unset unless otherwise specified,
set <var>controller</var>'s <a for="fetch controller">ongoing fetch params</a>
<a for="fetch params">terminated flag</a>, and set <var>controller</var>'s
<a for="fetch controller">ongoing fetch params</a> <a for="fetch params">aborted flag</a> if
<var>aborted</var> is set.

<p>To <dfn>queue a fetch task</dfn>, given an algorithm <var>algorithm</var>, a
<a for=/>global object</a> or a <a for=/>parallel queue</a> <var>taskDestination</var>, run these
steps:
Expand Down Expand Up @@ -2064,6 +2081,10 @@ known as an <dfn export id=concept-aborted-network-error>aborted network error</
<a for=response>header list</a> is always empty, and
<a for=response>body</a> is always null.

<p>To create the <dfn>appropriate network error</dfn> given <a for=/>fetch params</a>
<var>fetchParams</var>, return an <a>aborted network error</a> if <var>fetchParams</var>'s
<a for="fetch params">aborted flag</a> is set, otherwise return a <a>network error</a>.

<hr>

<p>A <dfn export id=concept-filtered-response>filtered response</dfn> is a limited view on a
Expand Down Expand Up @@ -3682,10 +3703,6 @@ accepting a <a for=/>response</a>. If given, <var>processResponseEndOfBody</var>
algorithm accepting a <a for=/>response</a> and null, failure, or a <a for=/>byte sequence</a>. If
given, <var>processResponseDone</var> must be an algorithm accepting a <a for=/>response</a>.

<p>An ongoing <a for=/>fetch</a> can be
<dfn export for=fetch id=concept-fetch-terminate>terminated</dfn> with flag <var>aborted</var>,
which is unset unless otherwise specified.

<p>The user agent may be asked to
<dfn export for=fetch id=concept-fetch-suspend>suspend</dfn> the ongoing fetch.
The user agent may either accept or ignore the suspension request. The suspended fetch can be
Expand Down Expand Up @@ -3740,6 +3757,14 @@ the request.
<a for="fetch params">cross-origin isolated capability</a> is
<var>crossOriginIsolatedCapability</var>.

<li><p>Let <var>controller</var> be a new <a for=/>fetch controller</a> with its
<a for="fetch controller">ongoing fetch params</a> set to <var>fetchParams</var>.</p></li>

<p>If this instance of <a for=/>fetch</a> is
<dfn export for=fetch id=concept-fetch-terminate>terminated</dfn> given flag <var>aborted</var>,
which is unset unless otherwise specified, <a for="fetch controller">terminate</a>
<var>controller</var> with <var>aborted</var>.

<li><p>If <var>request</var>'s <a for=request>body</a> is a <a for=/>byte sequence</a>, then set
<var>request</var>'s <a for=request>body</a> to the first return value of
<a for=BodyInit>safely extracting</a> <var>request</var>'s <a for=request>body</a>.
Expand Down Expand Up @@ -3821,6 +3846,8 @@ the request.
</ol>

<li><p>Run <a>main fetch</a> given <var>fetchParams</var>.

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


Expand Down Expand Up @@ -4266,16 +4293,8 @@ steps:
<li><p>Return <var>response</var>.
</ol>

<li>
<p><a>If aborted</a>, then:

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.

<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.

<li><p>Return a <a>network error</a>.
</ol>
<li><p><a>If aborted</a>, then return the <a for=/>appropriate network error</a> for
<var>fetchParams</var>.</p></li>
</ol>

<dt>"<code>data</code>"
Expand Down Expand Up @@ -5004,16 +5023,9 @@ steps. They return a <a for=/>response</a>.
</ol>
</ol>

<li>
<p><a>If aborted</a>, then:
<li><p><a>If aborted</a>, then return the <a for=/>appropriate network error</a> for
<var>fetchParams</var>.</p></li>

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.

<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.

<li><p>Return a <a>network error</a>.
</ol>

<!-- If response is still null, we require a forwarded request. -->
<li>
Expand Down Expand Up @@ -5106,16 +5118,8 @@ steps. They return a <a for=/>response</a>.
<var>isAuthenticationFetch</var> is true, then:

<ol>
<li>
<p>If the ongoing fetch is <a for=fetch>terminated</a>, then:

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.

<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.

<li><p>Return a <a>network error</a>.
</ol>
<li><p>If <var>fetchParams</var>'s <a for="fetch params">terminated flag</a> is set, then
return the <a for=/>appropriate network error</a> for <var>fetchParams</var>.</p></li>

<li><p>Let <var>username</var> and <var>password</var> be the result of prompting the end user
for a username and password, respectively, in <var>request</var>'s
Expand All @@ -5142,16 +5146,8 @@ steps. They return a <a for=/>response</a>.
<li class=XXX><p>Needs testing: multiple `<code>Proxy-Authenticate</code>` headers, missing,
parsing issues.

<li>
<p>If the ongoing fetch is <a for=fetch>terminated</a>, then:

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.

<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.

<li><p>Return a <a>network error</a>.
</ol>
<li><p>If <var>fetchParams</var>'s <a for="fetch params">terminated flag</a> is set, then
return the <a for=/>appropriate network error</a> for <var>fetchParams</var>.</p></li>

<li>
<p>Prompt the end user as appropriate in <var>request</var>'s
Expand Down Expand Up @@ -5180,16 +5176,8 @@ steps. They return a <a for=/>response</a>.
<p>then:

<ol>
<li>
<p>If the ongoing fetch is <a for=fetch>terminated</a>, then:

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.

<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.

<li><p>Return a <a>network error</a>.
</ol>
<li><p>If <var>fetchParams</var>'s <a for="fetch params">terminated flag</a> is set, then
return the <a for=/>appropriate network error</a> for <var>fetchParams</var>.</p></li>

<li><p>Set <var>response</var> to the result of running <a>HTTP-network-or-cache fetch</a> given
<var>fetchParams</var>, <var>isAuthenticationFetch</var>, and true.
Expand Down Expand Up @@ -5246,7 +5234,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
</dl>

<li>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:
<p>Run these steps, but <a>abort when</a> <var>fetchParams</var>'s
<a for="fetch params">terminated flag</a> is set:

<ol>
<li><p>If <var>connection</var> is failure, then return a <a>network error</a>.
Expand Down Expand Up @@ -5348,7 +5337,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
<p>Let <var>processBodyChunk</var> given <var>bytes</var> be these steps:

<ol>
<li><p>If the ongoing fetch is <a for=fetch>terminated</a>, then abort these steps.
<li><p>If <var>fetchParams</var>'s <a for="fetch params">terminated flag</a> is set, then
abort these steps.

<li><p>Run this step <a>in parallel</a>: transmit <var>bytes</var>.

Expand All @@ -5361,7 +5351,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
<p>Let <var>processEndOfBody</var> be these steps:

<ol>
<li><p>If the ongoing fetch is <a for=fetch>terminated</a>, then abort these steps.
<li><p>If <var>fetchParams</var>'s <a for="fetch params">terminated flag</a> is set, then
abort these steps.

<li><p>If <var>fetchParams</var>'s <a for="fetch params">process request end-of-body</a> is
non-null, then run <var>fetchParams</var>'s
Expand All @@ -5372,7 +5363,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
<p>Let <var>processBodyError</var> given <var>e</var> be these steps:

<ol>
<li><p>If the ongoing fetch is <a for=fetch>terminated</a>, then abort these steps.
<li><p>If <var>fetchParams</var>'s <a for="fetch params">terminated flag</a> is set, then
abort these steps.

<li><p>If <var>e</var> is an "<code><a exception>AbortError</a></code>" {{DOMException}},
then <a lt=terminated for=fetch>terminate</a> the ongoing fetch with the aborted flag set.
Expand All @@ -5394,7 +5386,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
<p><a>If aborted</a>, then:

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.
<li><p>Let <var>aborted</var> be <var>fetchParams</var>'s
<a for="fetch params">aborted flag</a>.

<li><p>If <var>connection</var> uses HTTP/2, then transmit an <code>RST_STREAM</code> frame.

Expand Down Expand Up @@ -5423,7 +5416,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
<a for="ReadableStream/set up"><var>sizeAlgorithm</var></a> set to <var>sizeAlgorithm</var>.

<li>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:
<p>Run these steps, but <a>abort when</a> <var>fetchParams</var>'s
<a for="fetch params">terminated flag</a> is set:

<ol>
<li><p>Set <var>response</var>'s <a for=response>body</a> to a new
Expand Down Expand Up @@ -5452,7 +5446,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
<p><a>If aborted</a>, then:

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.
<li><p>Let <var>aborted</var> be <var>fetchParams</var>'s
<a for="fetch params">aborted flag</a>.

<li><p>If <var>aborted</var> is set, then set <var>response</var>'s
<a for=response>aborted flag</a>.
Expand All @@ -5465,7 +5460,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:

<ol>
<li>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:
<p>Run these steps, but <a>abort when</a> <var>fetchParams</var>'s
<a for="fetch params">terminated flag</a> is set:

<ol>
<li>
Expand Down Expand Up @@ -5520,7 +5516,8 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:
<ol>
<li><a for=/>Finalize response</a> for <var>fetchParams</var> and <var>response</var>.

<li><p>Let <var>aborted</var> be the termination's aborted flag.
<li><p>Let <var>aborted</var> be <var>fetchParams</var>'s
<a for="fetch params">aborted flag</a>.

<li>
<p>If <var>aborted</var> is set, then:
Expand Down

0 comments on commit da4db3d

Please sign in to comment.