Skip to content

Commit afd98f1

Browse files
authored
Use extract a length from Fetch
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.
1 parent 231e282 commit afd98f1

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

xhr.bs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -783,28 +783,32 @@ return <a>this</a>'s <a>cross-origin credentials</a>.
783783
<li><p><a>Fire a progress event</a> named <a event><code>loadstart</code></a> at <a>this</a>
784784
with 0 and 0.
785785

786+
<li><p>Let <var>requestBodyTransmitted</var> be 0.
787+
788+
<li><p>Let <var>requestBodyLength</var> be <var>req</var>'s <a for=request>body</a>'s
789+
<a for=body>length</a>, if <var>req</var>'s <a for=request>body</a> is non-null; otherwise 0.
790+
791+
<li><p>Assert: <var>requestBodyLength</var> is an integer.
792+
786793
<li><p>If <a>this</a>'s <a>upload complete flag</a> is unset and <a>this</a>'s
787794
<a>upload listener flag</a> is set, then <a>fire a progress event</a> named
788-
<a event><code>loadstart</code></a> at <a>this</a>'s <a>upload object</a> with 0 and
789-
<var>req</var>'s <a for=request>body</a>'s <a>total bytes</a>.
795+
<a event><code>loadstart</code></a> at <a>this</a>'s <a>upload object</a> with
796+
<var>requestBodyTransmitted</var> and <var>requestBodyLength</var>.
790797

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

794-
<li><p>Let <var>uploadedBytesLength</var> be 0.
795-
796801
<li>
797802
<p>Let <var>processRequestBody</var>, given a <var>bytesLength</var>, be these steps:
798803

799804
<ol>
800-
<li><p>Increase <var>uploadedBytesLength</var> by <var>bytesLength</var>.
805+
<li><p>Increase <var>requestBodyTransmitted</var> by <var>bytesLength</var>.
801806

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

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

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

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

821-
<li><p>Let <var>length</var> be <var>req</var>'s
822-
<a for=request>body</a>'s
823-
<a>total bytes</a>.
824-
825825
<li><p><a>Fire a progress event</a> named <a event><code>progress</code></a> at <a>this</a>'s
826-
<a>upload object</a> with <var>uploadedBytesLength</var> and <var>length</var>.
826+
<a>upload object</a> with <var>requestBodyTransmitted</var> and <var>requestBodyLength</var>.
827827

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

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

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

856+
<li><p>Let <var>length</var> be the result of <a for="header list">extracting a length</a> from
857+
<a>this</a>'s <a for=XMLHttpRequest>response</a>'s <a for=response>header list</a>.
858+
859+
<li><p>If <var>length</var> is not an integer, then set it to 0.
860+
856861
<li>
857862
<p>Let <var>processBodyChunk</var> given <var>bytes</var> be these steps:
858863

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

873878
<li><p><a>Fire a progress event</a> named <a event><code>progress</code></a> at <a>this</a>
874879
with <a>this</a>'s <a>received bytes</a>'s <a for="byte sequence">length</a> and
875-
<a>this</a>'s <a for=XMLHttpRequest>response</a>'s <a for=response>body</a>'s
876-
<a>total bytes</a>.
880+
<var>length</var>.
877881
</ol>
878882

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

971-
<li><p>Let <var>length</var> be <var>xhr</var>'s <a for=XMLHttpRequest>response</a>'s
972-
<a for=response>body</a>'s <a for=body>total bytes</a>.
975+
<li><p>Let <var>length</var> be the result of <a for="header list">extracting a length</a> from
976+
<a>this</a>'s <a for=XMLHttpRequest>response</a>'s <a for=response>header list</a>.
977+
978+
<li><p>If <var>length</var> is not an integer, then set it to 0.
973979

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

0 commit comments

Comments
 (0)