Skip to content

Commit e3979c8

Browse files
committed
Initial resource timing integration.
Created a "fetch timing info" struct to hold the bookkeeping necessary for resource timing. Populated it with some of the required values, leaving some of them for later patches as this is a big undertaking. See w3c/resource-timing#252
1 parent 24a8670 commit e3979c8

File tree

1 file changed

+88
-14
lines changed

1 file changed

+88
-14
lines changed

fetch.bs

Lines changed: 88 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,34 @@ lt="authentication entry">authentication entries</a> (for HTTP authentication).
175175

176176
<dt><dfn for="fetch params">task destination</dfn> (default null)
177177
<dd>Null, a <a for=/>global object</a>, or a <a for=/>parallel queue</a>.
178+
<dt><dfn for="fetch params">timing info</dfn>
179+
<dd>A <a for=/>fetch timing info</a>.
178180
</dl>
179181

182+
<p>A <dfn>fetch timing info</dfn> is a <a for=/>struct</a> used to maintain timing information
183+
later required by the resource timing and navigation timiing specs. It has the following <a for=struct>items</a>:
184+
<dl>
185+
<dt><dfn for="fetch timing info">redirect start time</dfn> (default zero)
186+
<dt><dfn for="fetch timing info">redirect end time</dfn> (default zero)
187+
<dt><dfn for="fetch timing info">fetch start time</dfn> (default zero)
188+
<dt><dfn for="fetch timing info">response start time</dfn> (default zero)
189+
<dt><dfn for="fetch timing info">response end time</dfn> (default zero)
190+
<dt><dfn for="fetch timing info">alpn negotiated protocol</dfn> (default null)
191+
<dd>Null or a string.
192+
193+
<dt><dfn for="fetch timing info">worker start time</dfn> (default zero)
194+
<dt><dfn for="fetch timing info">domain lookup start time</dfn> (default zero)
195+
<dt><dfn for="fetch timing info">domain lookup end time</dfn> (default zero)
196+
<dt><dfn for="fetch timing info">connection start time</dfn> (default zero)
197+
<dt><dfn for="fetch timing info">connection end time</dfn> (default zero)
198+
<dt><dfn for="fetch timing info">secure connection start time</dfn> (default zero)
199+
<dt><dfn for="fetch timing info">request start time</dfn> (default zero)
200+
<dt><dfn for="fetch timing info">transfer size</dfn> (default zero)
201+
<dt><dfn for="fetch timing info">encoded body size</dfn> (default zero)
202+
<dt><dfn for="fetch timing info">decoded body size</dfn> (default zero)
203+
</dl>
204+
205+
180206
<p>To <dfn>queue a fetch task</dfn>, given an algorithm <var>algorithm</var>, a
181207
<a for=/>global object</a> or a <a for=/>parallel queue</a> <var>taskDestination</var>, run these
182208
steps:
@@ -1020,8 +1046,9 @@ worked on in <a href=https://github.com/whatwg/fetch/issues/1156>issue #1156</a>
10201046

10211047
<p>To <dfn export for=body>incrementally read</dfn> a <a for=/>body</a> <var>body</var>, given an
10221048
algorithm <var>processBodyChunk</var>, an algorithm <var>processEndOfBody</var>, an algorithm
1023-
<var>processBodyError</var>, and an optional null, <a for=/>parallel queue</a>, or
1024-
<a for=/>global object</a> <var>taskDestination</var> (default null), run these steps.
1049+
<var>processBodyError</var>, an optional null, <a for=/>parallel queue</a>, or
1050+
<a for=/>global object</a> <var>taskDestination</var> (default null), and an optional
1051+
<a for=/>fetch timing info</a> <var>timingInfo</var> or null (default null), run these steps.
10251052
<var>processBodyChunk</var> must be an algorithm accepting a <a for=/>byte sequence</a>.
10261053
<var>processEndOfBody</var> must be an algorithm accepting no arguments. <var>processBodyError</var>
10271054
must be an algorithm accepting an exception.
@@ -1037,14 +1064,15 @@ must be an algorithm accepting an exception.
10371064
<p class=note>This operation will not throw an exception.
10381065

10391066
<li><p>Perform the <a>incrementally-read loop</a> given <var>reader</var>,
1040-
<var>taskDestination</var>, <var>processBodyChunk</var>, <var>processEndOfBody</var>, and
1041-
<var>processBodyError</var>.
1067+
<var>taskDestination</var>, <var>processBodyChunk</var>, <var>processEndOfBody</var>,
1068+
<var>processBodyError</var> and <var>timingInfo</var>.
10421069
</ol>
10431070

10441071
<p>To perform the <dfn>incrementally-read loop</dfn>, given a {{ReadableStreamDefaultReader}} object
10451072
<var>reader</var>, <a for=/>parallel queue</a> or <a for=/>global object</a>
10461073
<var>taskDestination</var>, algorithm <var>processBodyChunk</var>, algorithm
1047-
<var>processEndOfBody</var>, and algorithm <var>processBodyError</var>:
1074+
<var>processEndOfBody</var>, algorithm <var>processBodyError</var>, and an optional
1075+
<a for=/>fetch timing info</a> <var>timingInfo</var> or null (default null):
10481076

10491077
<ol>
10501078
<li>
@@ -1055,6 +1083,9 @@ must be an algorithm accepting an exception.
10551083
<dd>
10561084
<ol>
10571085
<li><p>Let <var>continueAlgorithm</var> be null.
1086+
<li><p>If <var>timingInfo</var> is not null, and <var>timingInfo</var>'s
1087+
<a for="fetch timing info">response start time</a> is not zero, set <var>timingInfo</var>'s
1088+
<a for="fetch timing info">response start time</a> to the result of calling <a for=/>current time</a>.
10581089

10591090
<li><p>If <var>chunk</var> is not a {{Uint8Array}} object, then set
10601091
<var>continueAlgorithm</var> to this step: run <var>processBodyError</var> given a
@@ -1088,8 +1119,12 @@ must be an algorithm accepting an exception.
10881119
</ol>
10891120

10901121
<dt><a for="read request">close steps</a>
1091-
<dd><ol><li><p><a>Queue a fetch task</a> given <var>processEndOfBody</var> and
1092-
<var>taskDestination</var>.</ol>
1122+
<dd><ol>
1123+
<li><p><a>Queue a fetch task</a> given <var>processEndOfBody</var> and
1124+
<var>taskDestination</var>.
1125+
<li><p>If <var>timingInfo</var> is not null, set <var>timingInfo</var>'s
1126+
<a for="fetch timing info">response end time</a> to the result of calling <a for=/>current time</a>.
1127+
</ol>
10931128

10941129
<dt><a for="read request">error steps</a>, given <var>e</var>
10951130
<dd><ol><li><p><a>Queue a fetch task</a> to run <var>processBodyError</var> given <var>e</var>,
@@ -1136,6 +1171,9 @@ null), run these steps. <var>processBody</var> must be an algorithm accepting a
11361171
<var>reader</var>.
11371172
</ol>
11381173

1174+
<p class=XXX>TODO: set <a for="fetch timing info">response start time</a> and <a for="fetch timing info">response end time</a>
1175+
values for full reads. See <a href="https://github.com/w3c/resource-timing/issues/252">Issue 252</a>.
1176+
11391177
<hr>
11401178

11411179
<p>To <dfn export>handle content codings</dfn> given <var>codings</var> and <var>bytes</var>, run
@@ -1902,7 +1940,6 @@ initially unset.
19021940
allowed on the resource fetched by looking at the flag of the response returned. Because the flag on
19031941
the response of a redirect has to be set if it was set for previous responses in the redirect chain,
19041942
this is also tracked internally using the request's <a for=request>timing allow failed flag</a>.
1905-
19061943
<hr>
19071944

19081945
<p>A <a for=/>response</a> whose
@@ -2139,10 +2176,20 @@ identified by a <b>key</b> (a <a>network partition key</a>), an <b>origin</b> (a
21392176
<var>origin</var>. [[!HTTP]] [[!HTTP-SEMANTICS]] [[!HTTP-COND]] [[!HTTP-CACHING]] [[!HTTP-AUTH]]
21402177
[[!TLS]]
21412178

2179+
21422180
<p>If <var>credentials</var> is false, then do <em>not</em> send a TLS client certificate.
21432181

21442182
<p>If establishing a connection does not succeed (e.g., a DNS, TCP, or TLS error), then return
21452183
failure.
2184+
2185+
<p class=XXX>TODO: set <a for="fetch timing info">alpn negotiated protocol</a>,
2186+
<a for="fetch timing info">connection start time</a>,
2187+
<a for="fetch timing info">connection end time</a>,
2188+
<a for="fetch timing info">domain lookup start time</a>,
2189+
<a for="fetch timing info">domain lookup end time</a>,
2190+
<a for="fetch timing info">request start time</a>,
2191+
and <a for="fetch timing info">secure connection start time</a> values here.
2192+
See <a href="https://github.com/w3c/resource-timing/issues/252">Issue 252</a>.
21462193
</ol>
21472194

21482195
<li>
@@ -3272,6 +3319,7 @@ the request.
32723319

32733320
<li><p>Let <var>fetchParams</var> be a new <a for=/>fetch params</a> whose
32743321
<a for="fetch params">request</a> is <var>request</var>,
3322+
<a for="fetch params">timing info</a> is a new <a for=/>fetch timing info</a>,
32753323
<a for="fetch params">process request body</a> is <var>processRequestBody</var>,
32763324
<a for="fetch params">process request end-of-body</a> is <var>processRequestEndOfBody</var>,
32773325
<a for="fetch params">process response</a> is <var>processResponse</var>,
@@ -3348,6 +3396,8 @@ the request.
33483396
<li><p>Run <a>main fetch</a> given <var>fetchParams</var>.
33493397
</ol>
33503398

3399+
<h3 id="sec-current-time">Current Time</h3>
3400+
The <dfn>current time</dfn> is the present time given the <a for=/>global monotonic clock</a>.
33513401

33523402
<h3 id=main-fetch>Main fetch</h3>
33533403

@@ -3360,6 +3410,9 @@ steps:
33603410

33613411
<li><p>Let <var>response</var> be null.
33623412

3413+
<li><p>Set <var>fetchParams</var>'s <a for="fetch params">timing info</a>'s <a for="fetch timing info">fetch start time</a>
3414+
to the result of running <a for=/>current time</a>.
3415+
33633416
<li><p>If <var>request</var>'s <a>local-URLs-only flag</a> is set and <var>request</var>'s
33643417
<a for=request>current URL</a> is not <a lt="is local">local</a>, then set <var>response</var> to a
33653418
<a>network error</a>.
@@ -3684,8 +3737,7 @@ steps:
36843737

36853738
<li><p>Wait for either <var>response</var>'s <a for=response>body</a> to be null, or
36863739
<var>response</var>'s <a for=response>body</a>'s <a for=body>stream</a> to be
3687-
<a for=ReadableStream>closed</a> or <a for=ReadableStream>errored</a>, and then set
3688-
<var>request</var>'s <a>done flag</a>.
3740+
<a for=ReadableStream>closed</a> or <a for=ReadableStream>errored</a>, and set <var>request</var>'s <a>done flag</a>.
36893741
<!-- This is really bad and needs to be handled differently at some point. -->
36903742
</ol>
36913743

@@ -3812,6 +3864,8 @@ these steps:
38123864

38133865
<li><p>Let <var>actualResponse</var> be null.
38143866

3867+
<li><p>Let <var>timingInfo</var> be <var>fetchParams</var>'s <a for="fetch params">timing info</a>
3868+
38153869
<li>
38163870
<p>If <var>request</var>'s <a>service-workers mode</a> is "<code>all</code>", then:
38173871

@@ -3821,6 +3875,8 @@ these steps:
38213875

38223876
<li><p>Set <var>response</var> to the result of invoking <a for=/>handle fetch</a> for
38233877
<var>requestForServiceWorker</var>. [[!HTML]] [[!SW]]
3878+
<p class=XXX>TODO: set <a for="fetch timing info">worker start time</a> value.
3879+
See <a href="https://github.com/w3c/resource-timing/issues/252">Issue 252</a>.
38243880

38253881
<li>
38263882
<p>If <var>response</var> is not null, then:
@@ -3952,8 +4008,9 @@ these steps:
39524008
<a for="filtered response">internal response</a> is <var>actualResponse</var>.
39534009

39544010
<dt>"<code>follow</code>"
3955-
<dd><p>Set <var>response</var> to the result of running <a>HTTP-redirect fetch</a> given
3956-
<var>fetchParams</var> and <var>response</var>.
4011+
<dd><p>Set <var>timingInfo</var>'s <a for="fetch timing info">redirect start time</a> to
4012+
<var>timingInfo</var>'s <a for="fetch timing info">fetch start time</a>, and set <var>response</var> to
4013+
the result of running <a>HTTP-redirect fetch</a> given <var>fetchParams</var> and <var>response</var>.
39574014
</dl>
39584015
<!-- not resetting actualResponse since it's no longer used anyway -->
39594016
</ol>
@@ -4043,6 +4100,9 @@ run these steps:
40434100
<p class="note no-backref"><var>request</var>'s <a for=request>body</a>'s <a for=body>source</a>'s
40444101
nullity has already been checked.
40454102

4103+
<li><p>Set <var>fetchParams</var>'s <a for="fetch params">timing info</a>'s <a for="fetch timing info">redirect end time</a>
4104+
to the result of runnning <a for=/>current time</a>.
4105+
40464106
<li><p><a for=list>Append</a> <var>locationURL</var> to <var>request</var>'s
40474107
<a for=request>URL list</a>.
40484108

@@ -4720,8 +4780,9 @@ these steps:
47204780
</ol>
47214781

47224782
<li><p><a for=body>Incrementally read</a> <var>request</var>'s <a for=request>body</a> given
4723-
<var>processBodyChunk</var>, <var>processEndOfBody</var>, <var>processBodyError</var>, and
4724-
<var>fetchParams</var>'s <a for="fetch params">task destination</a>.
4783+
<var>processBodyChunk</var>, <var>processEndOfBody</var>, <var>processBodyError</var>,
4784+
<var>fetchParams</var>'s <a for="fetch params">task destination</a>, and
4785+
<var>fetchParams</var>'s <a for="fetch params">timing info</a>.
47254786
<!-- This obtains a reader in parallel, but it's mostly fine since we already proxied the
47264787
input stream as part of the Request constructor. -->
47274788
</ol>
@@ -4820,17 +4881,30 @@ these steps:
48204881

48214882
<ol>
48224883
<li><p>Let <var>bytes</var> be the transmitted bytes.
4884+
<li><p>Let <var>timingInfo</var> be the <var>fetchParams</var>'s <a for="fetch params">timing info</a>.
48234885

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

4889+
<li><p>Set <var>timingInfo</var>'s <a for="fetch timing info">transfer size</a> to the result of
4890+
adding <var>timingInfo</var>'s <a for="fetch timing info">transfer size</a> and <var>bytes</var>.
4891+
4892+
<p class=XXX>TODO: <a for="fetch timing info">transfer size</a> should also include the total size of the headers.
4893+
See <a href="https://github.com/w3c/resource-timing/issues/252">Issue 252</a>.
4894+
4895+
<li><p>Set <var>timingInfo</var>'s <a for="fetch timing info">encoded body size</a> to the result of
4896+
adding <var>timingInfo</var>'s <a for="fetch timing info">encoded body size</a> and <var>bytes</var>.
4897+
48274898
<li>
48284899
<p>Set <var>bytes</var> to the result of <a lt="handle content codings">handling content
48294900
codings</a> given <var>codings</var> and <var>bytes</var>.
48304901

48314902
<p class="note no-backref">This makes the `<code>Content-Length</code>` <a for=/>header</a>
48324903
unreliable to the extent that it was reliable to begin with.
48334904

4905+
<li><p>Set <var>timingInfo</var>'s <a for="fetch timing info">decoded body size</a> to the result of
4906+
adding <var>timingInfo</var>'s <a for="fetch timing info">decoded body size</a> and <var>bytes</var>.
4907+
48344908
<li><p>If <var>bytes</var> is failure, then <a lt=terminated for=fetch>terminate</a> the
48354909
ongoing fetch.
48364910

0 commit comments

Comments
 (0)