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.
  • Loading branch information
annevk committed Mar 2, 2021
1 parent 26f974f commit abcc9bd
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions xhr.bs
Original file line number Diff line number Diff line change
Expand Up @@ -783,16 +783,20 @@ 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>uploadedBytesLength</var> be 0.

<li><p>Let <var>totalUploadedBytesLength</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>'s <a for=body>length</a> is
non-null; otherwise 0.

<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>uploadedBytesLength</var> and <var>totalUploadedBytesLength</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:

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

<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>uploadedBytesLength</var> and <var>totalUploadedBytesLength</var>.
<!-- upload complete flag can never be set here I hope -->
</ol>

Expand All @@ -818,18 +821,17 @@ 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>uploadedBytesLength</var> and
<var>totalUploadedBytesLength</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>uploadedBytesLength</var> and
<var>totalUploadedBytesLength</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>uploadedBytesLength</var> and
<var>totalUploadedBytesLength</var>.
</ol>
<!-- upload complete flag can never be set here I hope -->

Expand All @@ -855,6 +857,11 @@ return <a>this</a>'s <a>cross-origin credentials</a>.
then run <a>handle response end-of-body</a> for <a>this</a> and <a>this</a>'s
<a for=XMLHttpRequest>response</a>, and then 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 @@ -874,8 +881,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 @@ -972,8 +978,10 @@ steps:
<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>response</var>'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 abcc9bd

Please sign in to comment.