Skip to content

Commit

Permalink
Report Resource Timing for EventSource and <track>
Browse files Browse the repository at this point in the history
Part of #6542.

This also improves the EventSource processing model in general to be more modern and rigorous.
  • Loading branch information
noamr authored Feb 27, 2022
1 parent f125068 commit 8107e8a
Showing 1 changed file with 39 additions and 51 deletions.
90 changes: 39 additions & 51 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#ok-status">ok status</dfn></li>
<li><dfn data-x="navigation-request" data-x-href="https://fetch.spec.whatwg.org/#navigation-request">navigation request</dfn></li>
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#concept-network-error">network error</dfn></li>
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#concept-aborted-network-error">aborted network error</dfn></li>
<li>`<dfn data-x="http-origin" data-x-href="https://fetch.spec.whatwg.org/#http-origin"><code>Origin</code></dfn>` header</li>
<li>`<dfn data-x-href="https://fetch.spec.whatwg.org/#http-cross-origin-resource-policy"><code>Cross-Origin-Resource-Policy</code></dfn>` header</li>
<li><dfn data-x-href="https://fetch.spec.whatwg.org/#process-response">process response</dfn></li>
Expand Down Expand Up @@ -34551,7 +34552,7 @@ interface <dfn interface>MediaError</dfn> {
<span>media element</span>'s <span>node document</span>'s <span>relevant settings
object</span>.</p>

<!--FETCH--><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.
<!--FETCH--><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p>

<p>The <var>response</var>'s <span>unsafe response</span> obtained in this fashion, if any,
contains the <span>media data</span>. It can be <span>CORS-same-origin</span> or
Expand Down Expand Up @@ -37822,7 +37823,11 @@ interface <dfn interface>VideoTrack</dfn> {
<code>track</code> element's <span>node document</span>'s <span>relevant settings
object</span>.</p></li>

<!--FETCH--><li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>
<!--FETCH--><li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>, with <i
data-x="processResponseEndOfBody">processResponseEndOfBody</i> given <span
data-x="concept-response">response</span> <var>res</var> set to <span>finalize and report
timing</span> with <var>res</var>, the element's <span>node document</span>'s <span>relevant
global object</span>, and "<code data-x="">track</code>".</p></li>
</ol>

<p>The <span data-x="concept-task">tasks</span> <span data-x="queue a task">queued</span> by the
Expand Down Expand Up @@ -100096,12 +100101,42 @@ dictionary <dfn dictionary>EventSourceInit</dfn> {
<li><p>Set <var>ev</var>'s <span data-x="concept-event-stream-request">request</span> to
<var>request</var>.</p></li>

<li><p>Let <var>finalizeEventSourceFetch</var> given <span
data-x="concept-response">response</span> <var>res</var> be to <span>finalize and report
timing</span> with <var>res</var>, <var>settings</var>'s <span
data-x="concept-settings-object-global">global object</span>, and "<code
data-x="">other</code>".</p></li>

<li><p>Let <var>processEventSourceEndOfBody</var> given <span
data-x="concept-response">response</span> <var>res</var> be the following step: if
<var>res</var> is not a <span>network error</span>, then <var>finalizeEventSourceFetch</var>
with <var>res</var>, and <span>reestablish the connection</span>.</p></li>

<li>
<p>Run this step <span>in parallel</span>:</p>
<p><span data-x="concept-fetch">Fetch</span> <var>request</var> with <i
data-x="processResponseEndOfBody">processResponseEndOfBody</i> set to
<var>processEventSourceEndOfBody</var> and <i data-x="process response">processResponse</i> set
to the following steps given <span data-x="concept-response">response</span>
<var>res</var>:</p>

<ol>
<!--FETCH--><li><p><span data-x="concept-fetch">Fetch</span> <var>request</var>.</p></li>
<li><p>If <var>res</var> is an <span>aborted network error</span>, then <span>fail the
connection</span>.</p></li>

<li><p>Otherwise, if <var>res</var> is a <span>network error</span>, then call
<var>finalizeEventSourceFetch</var> given <var>res</var>, and <span>reestablish the
connection</span>, unless the user agent knows that to be futile, in which case the user agent
may <span>fail the connection</span>.</p></li>

<li><p>Otherwise, if <var>res</var>'s <span data-x="concept-response-status">status</span> is
not 200, or if <var>res</var>'s `<code>Content-Type</code>` is not
`<code>text/event-stream</code>`, then <span>fail the connection</span>.</p>

<li><p>Otherwise, <span>announce the connection</span> and <a
href="#event-stream-interpretation">interpret</a> <var>res</var>'s <span
data-x="concept-response-body">body</span> line by line.</p></li>
</ol>
</li>

<li><p>Return <var>ev</var>.</p></li>
</ol>
Expand Down Expand Up @@ -100174,53 +100209,6 @@ dictionary <dfn dictionary>EventSourceInit</dfn> {

<h4 id="sse-processing-model"><span id="processing-model-9"></span>Processing model</h4>

<p>The resource indicated in the argument to the <code data-x="dom-EventSource">EventSource</code>
constructor is fetched when the constructor is run.</p>

<p>As data is received, the <span data-x="concept-task">tasks</span> queued by the <span>networking
task source</span> to handle the data must act as follows.</p>

<p>HTTP 200 OK responses with a `<code>Content-Type</code>` header specifying the type
`<code>text/event-stream</code>`, ignoring any <span>MIME type</span> parameters, must be
processed line by line <a href="#event-stream-interpretation">as described below</a>.</p>

<p>When a successful response with a supported <span>MIME type</span> is received, such that the
user agent begins parsing the contents of the stream, the user agent must <span>announce the
connection</span>.</p>

<p>The <span data-x="concept-task">task</span> that the <span>networking task source</span> places
on the <span>task queue</span> once fetching for such a resource (with the correct <span>MIME
type</span>) has completed must cause the user agent to <span>reestablish the connection</span>
<span>in parallel</span>. This applies whether the connection is closed gracefully or unexpectedly
(but does not apply when fetching is canceled by the user agent, e.g., in response to <code
data-x="dom-window-stop">window.stop()</code>, since in those cases the final <span
data-x="concept-task">task</span> is actually discarded). It doesn't apply for the error
conditions listed below except where explicitly specified.</p>

<p>HTTP 200 OK responses that have a <span>Content-Type</span> specifying an unsupported type, or
that have no <span>Content-Type</span> at all, must cause the user agent to <span>fail the
connection</span>.</p> <!-- about:blank is defined as having no MIME type -->

<p id="event-source-network-errors-reconnect">Network errors that prevents the connection from
being established in the first place (e.g. DNS errors), should cause the user agent to
<span>reestablish the connection</span> <span>in parallel</span>, unless the user agent knows that
to be futile, in which case the user agent may <span>fail the connection</span>.</p>

<p id="event-source-fail-reasons">Any other HTTP response code not listed here, as well as the
cancelation of the fetch algorithm by the user agent (e.g. in response to <code
data-x="dom-window-stop">window.stop()</code> or the user canceling the network connection
manually) must cause the user agent to <span>fail the connection</span>.</p> <!-- including: HTTP
201 Created, 202 Accepted, 203 Non-Authoritative Information, 204 No Content, 205 Reset Content,
206 Partial Content, 300 Multiple Choices, 304 Not Modified, 400 Bad Request, 403 Forbidden, 404
Not Found, 405 Method Not Allowed, 406 Not Acceptable, 408 Request Timeout, 409 Conflict, 410
Gone, 411 Length Required, 412 Precondition Failed, 413 Request Entity Too Large, 414 Request-URI
Too Long, 415 Unsupported Media Type, 416 Requested Range Not Satisfiable, 417 Expectation Failed,
HTTP 500 Internal Server Error, 501 Not Implemented, 502 Bad Gateway, 503 Service Unavailable, and
504 Gateway Timeout responses, and 505 HTTP Version Not Supported responses --> <!-- mailto: is
defined as equivalent to HTTP 204 -->

<hr>

<p>When a user agent is to <dfn>announce the connection</dfn>, the user agent must <span>queue a
task</span> which, if the <code data-x="dom-EventSource-readyState">readyState</code> attribute is
set to a value other than <code data-x="dom-EventSource-CLOSED">CLOSED</code>, sets the <code
Expand Down

0 comments on commit 8107e8a

Please sign in to comment.