Skip to content

Commit

Permalink
Create timing info for HTTP(S) network errors
Browse files Browse the repository at this point in the history
  • Loading branch information
noamr authored and ericorth committed Feb 18, 2022
1 parent 486e626 commit 77bafd3
Showing 1 changed file with 63 additions and 17 deletions.
80 changes: 63 additions & 17 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -4210,11 +4210,68 @@ 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>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
<a for="fetch params">task destination</a>.

<li><p>If <var>response</var>'s <a for=response>body</a> is null, then run
<var>processResponseDone</var>.

<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
<a for="TransformStream/set up"><i>transformAlgorithm</i></a> set to <var>identityTransformAlgorithm</var> and
<a for="TransformStream/set up"><i>flushAlgorithm</i></a> 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>

<p class=note>This {{TransformStream}} is needed for the purpose of receiving a notification when
the stream reaches its end, and is otherwise an <a>identity transform stream</a>.

<li>
<p>If <var>fetchParams</var>'s <a for="fetch params">process response end-of-body</a> is non-null,
then:
Expand All @@ -4237,24 +4294,13 @@ steps:
</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>.
</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 @@ -4264,6 +4310,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 @@ -5596,17 +5645,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

0 comments on commit 77bafd3

Please sign in to comment.