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

Attach timing info and URL to network errors, and report for fetch API #1311

Merged
merged 17 commits into from
Dec 13, 2021
82 changes: 65 additions & 17 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -4194,6 +4194,64 @@ steps:
<a for=/>response</a> <var>response</var>, run these steps:

<ol>
<li>
<p>If <var>response</var> is a <a>network error</a>, then:

<ol>
<li>
<p>Set <var>response</var>'s <a for=response>URL list</a> to « <var>fetchParams</var>'s
<a for="fetch params">request</a>'s <a for=request>URL list</a>[0] ≫.

<p class=note>This is needed as after <a for=list>cloning</a> <var>fetchParams</var>'s
<a for="fetch params">request</a>'s <a for=request>URL list</a> earlier, <var>response</var>
might have been set to a <a>network error</a>.</p>
</li>

<li><p>Set <var>response</var>'s <a for=response>timing info</a> to the result of
<a>creating an opaque timing info</a> for <var>fetchParams</var>'s
<a for="fetch params">timing info</a>.</p></li>
</ol>
</li>

<li>
<p>Let <var>processResponseDone</var> be the following steps:

<ol>
<li><p>Set <var>fetchParams</var>'s <a for="fetch params">request</a>'s
<a for=request>done flag</a>.

<li><p>If <var>fetchParams</var>'s <a for="fetch params">process response done</a> is not null,
then <a>queue a fetch task</a> to run <var>fetchParams</var>'s
<a for="fetch params">process response done</a> given <var>response</var> with
<var>fetchParams</var>'s <a for="fetch params">task destination</a>.
</ol>
</li>

<li><p>If <var>response</var>'s <a for=response>body</a> is null, then run
<var>processResponseDone</var>.
annevk marked this conversation as resolved.
Show resolved Hide resolved

<li>
<p>Otherwise:</p>

<ol>
<li><p>Let <var>transformStream</var> be a new a {{TransformStream}}.

<li><p>Let <var>identityTransformAlgorithm</var> be an algorithm which, given <var>chunk</var>,
<a for=TransformStream lt=enqueue>enqueues</a> <var>chunk</var> in <var>transformStream</var>.

<li><p><a for=TransformStream lt="setting up">Set up</a> <var>transformStream</var> with
[=TransformStream/set up/transformalgorithm=] set to <var>identityTransformAlgorithm</var> and
annevk marked this conversation as resolved.
Show resolved Hide resolved
[=TransformStream/set up/flushalgorithm=] set to <var>processResponseDone</var>.

<li><p>Set <var>response</var>'s <a for=response>body</a> to the result of
<a for=ReadableStream lt="piping through">piping</a> <var>response</var>'s
<a for=response>body</a> through <var>transformStream</var>.
</ol>
noamr marked this conversation as resolved.
Show resolved Hide resolved

<p class=note>This {{TransformStream}} is needed for the purpose of receiving a notification when
the stream reaches its end, and is otherwise an [=identity transform stream=].
annevk marked this conversation as resolved.
Show resolved Hide resolved
</li>
annevk marked this conversation as resolved.
Show resolved Hide resolved

<li><p>If <var>fetchParams</var>'s <a for="fetch params">process response</a> is non-null, then
<a>queue a fetch task</a> to run <var>fetchParams</var>'s
<a for="fetch params">process response</a> given <var>response</var>, with <var>fetchParams</var>'s
Expand All @@ -4219,26 +4277,16 @@ steps:
<var>processBody</var>, <var>processBodyError</var>, and <var>fetchParams</var>'s
<a for="fetch params">task destination</a>.
</ol>
</ol>

<p>To <dfn>finalize response</dfn> given a <a for=/>fetch params</a> <var>fetchParams</var> and a
<a for=/>response</a> <var>response</var>, run these steps:

<ol>
<li><p>Set <var>fetchParams</var>'s <a for="fetch params">request</a>'s
<a for=request>done flag</a>.

<li><p>If <var>fetchParams</var>'s <a for="fetch params">process response done</a> is not null,
then <a>queue a fetch task</a> to run <var>fetchParams</var>'s
<a for="fetch params">process response done</a> given <var>response</var>,
with <var>fetchParams</var>'s <a for="fetch params">task destination</a>.
</li>
annevk marked this conversation as resolved.
Show resolved Hide resolved
</ol>

<p>To <dfn export>finalize and report timing</dfn> given a <a for=/>response</a>
<var>response</var>, a <a for=/>global object</a> <var>global</var>, and a <a for=/>string</a>
<var>initiatorType</var> (default "<code>other</code>"), run these steps:

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

<li><p>If <var>response</var>'s <a for=response>URL list</a> is null or
<a for=list lt="is empty">empty</a>, then return.

Expand All @@ -4248,6 +4296,9 @@ steps:

<li><p>Let <var>cacheState</var> be <var>response</var>'s <a for=response>cache state</a>.

<li><p>If <var>originalURL</var>'s <a for=url>scheme</a> is not an <a>HTTP(S) scheme</a>, then
return.

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

<li>
Expand Down Expand Up @@ -5580,17 +5631,14 @@ optional boolean <var>forceNewConnection</var> (default false), run these steps:

<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 for=ReadableStream>close</a> <var>stream</var>, <a for=/>finalize response</a> for
<var>fetchParams</var> and <var>response</var>, and abort these in-parallel steps.
<a for=ReadableStream>close</a> <var>stream</var>, and abort these in-parallel steps.
</ol>
</ol>

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

<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>
Expand Down