Skip to content

Commit

Permalink
Use extract a length from Fetch
Browse files Browse the repository at this point in the history
The only information browsers use for progress events for responses is the Content-Length header.

Align on that and only use body's length concept for uploads.

Tests: web-platform-tests/wpt#27837.

Fetch PRs: whatwg/fetch#1183 & whatwg/fetch#1184.

Closes whatwg/fetch#604.
  • Loading branch information
annevk authored Mar 11, 2021
1 parent 231e282 commit afd98f1
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions xhr.bs
Original file line number Diff line number Diff line change
Expand Up @@ -783,28 +783,32 @@ return <a>this</a>'s <a>cross-origin credentials</a>.
<li><p><a>Fire a progress event</a> named <a event><code>loadstart</code></a> at <a>this</a>
with 0 and 0.

<li><p>Let <var>requestBodyTransmitted</var> be 0.

<li><p>Let <var>requestBodyLength</var> be <var>req</var>'s <a for=request>body</a>'s
<a for=body>length</a>, if <var>req</var>'s <a for=request>body</a> is non-null; otherwise 0.

<li><p>Assert: <var>requestBodyLength</var> is an integer.

<li><p>If <a>this</a>'s <a>upload complete flag</a> is unset and <a>this</a>'s
<a>upload listener flag</a> is set, then <a>fire a progress event</a> named
<a event><code>loadstart</code></a> at <a>this</a>'s <a>upload object</a> with 0 and
<var>req</var>'s <a for=request>body</a>'s <a>total bytes</a>.
<a event><code>loadstart</code></a> at <a>this</a>'s <a>upload object</a> with
<var>requestBodyTransmitted</var> and <var>requestBodyLength</var>.

<li><p>If <a>this</a>'s <a>state</a> is not <i>opened</i> or <a>this</a>'s
<a><code>send()</code> flag</a> is unset, then return.

<li><p>Let <var>uploadedBytesLength</var> be 0.

<li>
<p>Let <var>processRequestBody</var>, given a <var>bytesLength</var>, be these steps:

<ol>
<li><p>Increase <var>uploadedBytesLength</var> by <var>bytesLength</var>.
<li><p>Increase <var>requestBodyTransmitted</var> by <var>bytesLength</var>.

<li><p>If not roughly 50ms have passed since these steps were last invoked, then return.

<li><p>If <a>this</a>'s <a>upload listener flag</a> is set, then <a>fire a progress event</a>
named <a event><code>progress</code></a> at <a>this</a>'s <a>upload object</a> with
<var>uploadedBytesLength</var> and <var>req</var>'s <a for=request>body</a>'s
<a>total bytes</a>.
<var>requestBodyTransmitted</var> and <var>requestBodyLength</var>.
<!-- upload complete flag can never be set here I hope -->
</ol>

Expand All @@ -818,18 +822,14 @@ return <a>this</a>'s <a>cross-origin credentials</a>.

<li><p>If <a>this</a>'s <a>upload listener flag</a> is unset, then return.

<li><p>Let <var>length</var> be <var>req</var>'s
<a for=request>body</a>'s
<a>total bytes</a>.

<li><p><a>Fire a progress event</a> named <a event><code>progress</code></a> at <a>this</a>'s
<a>upload object</a> with <var>uploadedBytesLength</var> and <var>length</var>.
<a>upload object</a> with <var>requestBodyTransmitted</var> and <var>requestBodyLength</var>.

<li><p><a>Fire a progress event</a> named <a event><code>load</code></a> at <a>this</a>'s
<a>upload object</a> with <var>uploadedBytesLength</var> and <var>length</var>.
<a>upload object</a> with <var>requestBodyTransmitted</var> and <var>requestBodyLength</var>.

<li><p><a>Fire a progress event</a> named <a event><code>loadend</code></a> at <a>this</a>'s
<a>upload object</a> with <var>uploadedBytesLength</var> and <var>length</var>.
<a>upload object</a> with <var>requestBodyTransmitted</var> and <var>requestBodyLength</var>.
</ol>
<!-- upload complete flag can never be set here I hope -->

Expand All @@ -853,6 +853,11 @@ return <a>this</a>'s <a>cross-origin credentials</a>.
<li><p>If <a>this</a>'s <a for=XMLHttpRequest>response</a>'s <a for=response>body</a> is null,
then run <a>handle response end-of-body</a> for <a>this</a> and return.

<li><p>Let <var>length</var> be the result of <a for="header list">extracting a length</a> from
<a>this</a>'s <a for=XMLHttpRequest>response</a>'s <a for=response>header list</a>.

<li><p>If <var>length</var> is not an integer, then set it to 0.

<li>
<p>Let <var>processBodyChunk</var> given <var>bytes</var> be these steps:

Expand All @@ -872,8 +877,7 @@ return <a>this</a>'s <a>cross-origin credentials</a>.

<li><p><a>Fire a progress event</a> named <a event><code>progress</code></a> at <a>this</a>
with <a>this</a>'s <a>received bytes</a>'s <a for="byte sequence">length</a> and
<a>this</a>'s <a for=XMLHttpRequest>response</a>'s <a for=response>body</a>'s
<a>total bytes</a>.
<var>length</var>.
</ol>

<li><p>Let <var>processEndOfBody</var> be this step: run <a>handle response end-of-body</a> for
Expand Down Expand Up @@ -968,8 +972,10 @@ return <a>this</a>'s <a>cross-origin credentials</a>.
<li><p>Let <var>transmitted</var> be <var>xhr</var>'s <a>received bytes</a>'s
<a for="byte sequence">length</a>.

<li><p>Let <var>length</var> be <var>xhr</var>'s <a for=XMLHttpRequest>response</a>'s
<a for=response>body</a>'s <a for=body>total bytes</a>.
<li><p>Let <var>length</var> be the result of <a for="header list">extracting a length</a> from
<a>this</a>'s <a for=XMLHttpRequest>response</a>'s <a for=response>header list</a>.

<li><p>If <var>length</var> is not an integer, then set it to 0.

<li><p>If <var>xhr</var>'s <a>synchronous flag</a> is unset, then <a>fire a progress event</a>
named <a event><code>progress</code></a> at <var>xhr</var> with <var>transmitted</var> and
Expand Down

0 comments on commit afd98f1

Please sign in to comment.