Skip to content

Commit

Permalink
Use Infra's abort when
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk committed Apr 26, 2018
1 parent 0dec453 commit 9f944e1
Showing 1 changed file with 74 additions and 60 deletions.
134 changes: 74 additions & 60 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,7 +1233,7 @@ or "<code>worker</code>".

<ol>
<li>
<p>Run these steps, but abort if the ongoing fetch is <a for=fetch>terminated</a>:</p>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>
<li><p>Wait for <var>read</var> to be fulfilled or rejected.
Expand Down Expand Up @@ -1270,7 +1270,7 @@ or "<code>worker</code>".
<li><p>Otherwise, <a lt=terminated for=fetch>terminate</a> the ongoing fetch.
</ol>

<li><p>If the ongoing fetch is <a for=fetch>terminated</a>, then abort these in-parallel steps.
<li><p><a>If aborted</a>, then abort these in-parallel steps.
</ol>
</ol>

Expand Down Expand Up @@ -1566,7 +1566,7 @@ for each associated <a for="fetch group">fetch record</a> whose
<li><p>Let <var>connection</var> be null.

<li>
<p>Run these steps, but abort if the ongoing fetch is <a for=fetch>terminated</a>:</p>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>
<li>
Expand All @@ -1581,7 +1581,7 @@ for each associated <a for="fetch group">fetch record</a> whose
</ol>

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

<ol>
<li><p>If <var>connection</var> is not null, then close <var>connection</var>.
Expand Down Expand Up @@ -2403,7 +2403,7 @@ the request.

<ol>
<li>
<p>Run these steps, but abort if the ongoing fetch is <a for=fetch>terminated</a>:</p>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>
<li><p>If <var>request</var>'s <a for=request>window</a> is
Expand Down Expand Up @@ -2528,7 +2528,7 @@ the request.
</ol>

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

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.
Expand All @@ -2555,7 +2555,7 @@ with a <i>CORS flag</i> and <i>recursive flag</i>, run these steps:
<li><p>Let <var>response</var> be null.

<li>
<p>Run these steps, but abort if the ongoing fetch is <a for=fetch>terminated</a>:</p>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>

Expand Down Expand Up @@ -2637,7 +2637,7 @@ with a <i>CORS flag</i> and <i>recursive flag</i>, run these steps:
</ol>

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

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.
Expand Down Expand Up @@ -2926,7 +2926,7 @@ steps:
<dd>
<ol>
<li>
<p>Run these steps, but abort if the ongoing fetch is <a for=fetch>terminated</a>:
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>
<li><p>Let <var>blob</var> be <var>request</var>'s
Expand Down Expand Up @@ -2969,11 +2969,16 @@ steps:
<li><p>Return <var>response</var>.
</ol>

<li><p>Let <var>aborted</var> be the termination's aborted flag.
<li>
<p><a>If aborted</a>, then:

<li><p>If <var>aborted</var> is set, then return an <a>aborted network error</a>.
<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.

<li><p>Return a <a>network error</a>.
<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>
</ol>

<dt>"<code>data</code>"
Expand Down Expand Up @@ -3305,7 +3310,7 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
<li><p>Let <var>httpRequest</var> be null.

<li>
<p>Run these steps, but abort if the ongoing fetch is <a for=fetch>terminated</a>:</p>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>
<li><p>If <var>request</var>'s <a for=request>window</a> is "<code>no-window</code>" and
Expand Down Expand Up @@ -3580,7 +3585,7 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
</ol>

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

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.
Expand Down Expand Up @@ -3768,7 +3773,7 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b


<li>
<p>Run these steps, but abort if the ongoing fetch is <a for=fetch>terminated</a>:</p>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>
<li><p>If <var>connection</var> is failure, return a
Expand Down Expand Up @@ -3833,7 +3838,7 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
</ol>

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

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.
Expand Down Expand Up @@ -3865,7 +3870,7 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
<p class="note no-backref">This construction operation will not throw an exception.

<li>
<p>Run these steps, but abort if the ongoing fetch is <a for=fetch>terminated</a>:</p>
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>
<li><p>Set <var>response</var>'s <a for=response>body</a> to a new
Expand Down Expand Up @@ -3925,7 +3930,7 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b
</ol>

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

<ol>
<li><p>Let <var>aborted</var> be the termination's aborted flag.
Expand All @@ -3941,71 +3946,80 @@ Range Requests</cite>. [[HTTP-RANGE]] However, this is not widely supported by b

<ol>
<li>
<p>While true, breaking if the ongoing fetch <a for=fetch lt=terminated>terminates</a>:
<p>Run these steps, but <a>abort when</a> the ongoing fetch is <a for=fetch>terminated</a>:

<ol>
<li>
<p>If one or more bytes have been transmitted from <var>response</var>'s message body, then:
<p>While true:

<ol>
<li><p>Let <var>bytes</var> be the transmitted bytes.

<li><p>Increase <var>response</var>'s <a for=response>body</a>'s <a for=body>transmitted
bytes</a> with <var>bytes</var>' length.
<li>
<p>If one or more bytes have been transmitted from <var>response</var>'s message body, then:

<li><p>Let <var>codings</var> be the result of <a>extracting header list values</a> given
`<code>Content-Encoding</code>` and <var>response</var>'s <a for=response>header list</a>.
<ol>
<li><p>Let <var>bytes</var> be the transmitted bytes.

<li>
<p>Set <var>bytes</var> to the result of <a lt="handle content codings">handling content
codings</a> given <var>codings</var> and <var>bytes</var>.
<li><p>Increase <var>response</var>'s <a for=response>body</a>'s <a for=body>transmitted
bytes</a> with <var>bytes</var>' length.

<p class="note no-backref">This makes the `<code>Content-Length</code>` <a for=/>header</a>
unreliable to the extent that it was reliable to begin with.
<li><p>Let <var>codings</var> be the result of <a>extracting header list values</a> given
`<code>Content-Encoding</code>` and <var>response</var>'s <a for=response>header list</a>.

<li><p>If <var>bytes</var> is failure, then <a>terminate</a> the ongoing fetch.
<li>
<p>Set <var>bytes</var> to the result of <a lt="handle content codings">handling content
codings</a> given <var>codings</var> and <var>bytes</var>.

<li><p><a for=ReadableStream>Enqueue</a> a <code>Uint8Array</code> object wrapping an
<code>ArrayBuffer</code> containing <var>bytes</var> to <var>stream</var>. If that threw an
exception, <a lt=terminated for=fetch>terminate</a> the ongoing fetch, and
<a abstract-op>error</a> <var>stream</var> with that exception.
<p class="note no-backref">This makes the `<code>Content-Length</code>` <a for=/>header</a>
unreliable to the extent that it was reliable to begin with.

<li><p>If <var>stream</var> doesn't <a lt="need more data" for=ReadableStream>need more
data</a> and <var>request</var>'s <a>synchronous flag</a> is unset, ask the user agent to <a
for=fetch>suspend</a> the ongoing fetch.
</ol>
<li><p>If <var>bytes</var> is failure, then <a lt=terminated for=fetch>terminate</a> the
ongoing fetch.

<li><p>Otherwise, if the bytes transmission for <var>response</var>'s message body is done
normally and <var>stream</var> is <a for=ReadableStream>readable</a>, then
<a abstract-op>close</a> <var>stream</var> and abort these in-parallel steps.
</ol>
<li><p><a for=ReadableStream>Enqueue</a> a <code>Uint8Array</code> object wrapping an
<code>ArrayBuffer</code> containing <var>bytes</var> to <var>stream</var>. If that threw an
exception, <a lt=terminated for=fetch>terminate</a> the ongoing fetch, and
<a abstract-op>error</a> <var>stream</var> with that exception.

<p class=note>The following steps can only occur if the ongoing fetch terminates.
<li><p>If <var>stream</var> doesn't <a lt="need more data" for=ReadableStream>need more
data</a> and <var>request</var>'s <a>synchronous flag</a> is unset, ask the user agent to
<a for=fetch>suspend</a> the ongoing fetch.
</ol>

<li><p>Let <var>aborted</var> be the termination's aborted flag.
<li><p>Otherwise, if the bytes transmission for <var>response</var>'s message body is done
normally and <var>stream</var> is <a for=ReadableStream>readable</a>, then
<a abstract-op>close</a> <var>stream</var> and abort these in-parallel steps.
</ol>
</ol>

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

<ol>
<li><p>Set <var>response</var>'s <a for=response>aborted flag</a>.
<li><p>Let <var>aborted</var> be the termination's aborted flag.

<li><p>If <var>stream</var> is <a for=ReadableStream>readable</a>, <a abstract-op>error</a>
<var>stream</var> with an "<code><a exception>AbortError</a></code>" {{DOMException}}.
</ol>
<li>
<p>If <var>aborted</var> is set, then:

<li><p>Otherwise, if <var>stream</var> is <a for=ReadableStream>readable</a>,
<a abstract-op>error</a> <var>stream</var> with a <code>TypeError</code>.
<ol>
<li><p>Set <var>response</var>'s <a for=response>aborted flag</a>.

<li><p>If <var>connection</var> uses HTTP/2, then transmit an <code>RST_STREAM</code> frame.
<li><p>If <var>stream</var> is <a for=ReadableStream>readable</a>, <a abstract-op>error</a>
<var>stream</var> with an "<code><a exception>AbortError</a></code>" {{DOMException}}.
</ol>

<li>
<p>Otherwise, the user agent should close <var>connection</var> unless it would be bad for
performance to do so.
<li><p>Otherwise, if <var>stream</var> is <a for=ReadableStream>readable</a>,
<a abstract-op>error</a> <var>stream</var> with a <code>TypeError</code>.

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

<p class=note>For instance, the user agent could keep the connection open if it knows there's
only a few bytes of transfer remaining on a reusable connection. In this case it could be worse
to close the connection and go through the handshake process again for the next fetch.
<li>
<p>Otherwise, the user agent should close <var>connection</var> unless it would be bad for
performance to do so.

<p class=note>For instance, the user agent could keep the connection open if it knows there's
only a few bytes of transfer remaining on a reusable connection. In this case it could be
worse to close the connection and go through the handshake process again for the next fetch.
</ol>
</ol>

<p class="note no-backref">These are run <a>in parallel</a> as at this point it is unclear whether
Expand Down

0 comments on commit 9f944e1

Please sign in to comment.