From afd98f1336f8b637f700797006079a66e4d2c24a Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Thu, 11 Mar 2021 13:08:09 +0100 Subject: [PATCH] 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: https://github.com/web-platform-tests/wpt/pull/27837. Fetch PRs: https://github.com/whatwg/fetch/pull/1183 & https://github.com/whatwg/fetch/pull/1184. Closes https://github.com/whatwg/fetch/issues/604. --- xhr.bs | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/xhr.bs b/xhr.bs index b5c3cb4..bcd47ea 100644 --- a/xhr.bs +++ b/xhr.bs @@ -783,28 +783,32 @@ return this's cross-origin credentials.
  • Fire a progress event named loadstart at this with 0 and 0. +

  • Let requestBodyTransmitted be 0. + +

  • Let requestBodyLength be req's body's + length, if req's body is non-null; otherwise 0. + +

  • Assert: requestBodyLength is an integer. +

  • If this's upload complete flag is unset and this's upload listener flag is set, then fire a progress event named - loadstart at this's upload object with 0 and - req's body's total bytes. + loadstart at this's upload object with + requestBodyTransmitted and requestBodyLength.

  • If this's state is not opened or this's send() flag is unset, then return. -

  • Let uploadedBytesLength be 0. -

  • Let processRequestBody, given a bytesLength, be these steps:

      -
    1. Increase uploadedBytesLength by bytesLength. +

    2. Increase requestBodyTransmitted by bytesLength.

    3. If not roughly 50ms have passed since these steps were last invoked, then return.

    4. If this's upload listener flag is set, then fire a progress event named progress at this's upload object with - uploadedBytesLength and req's body's - total bytes. + requestBodyTransmitted and requestBodyLength.

    @@ -818,18 +822,14 @@ return this's cross-origin credentials.
  • If this's upload listener flag is unset, then return. -

  • Let length be req's - body's - total bytes. -

  • Fire a progress event named progress at this's - upload object with uploadedBytesLength and length. + upload object with requestBodyTransmitted and requestBodyLength.

  • Fire a progress event named load at this's - upload object with uploadedBytesLength and length. + upload object with requestBodyTransmitted and requestBodyLength.

  • Fire a progress event named loadend at this's - upload object with uploadedBytesLength and length. + upload object with requestBodyTransmitted and requestBodyLength. @@ -853,6 +853,11 @@ return this's cross-origin credentials.

  • If this's response's body is null, then run handle response end-of-body for this and return. +

  • Let length be the result of extracting a length from + this's response's header list. + +

  • If length is not an integer, then set it to 0. +

  • Let processBodyChunk given bytes be these steps: @@ -872,8 +877,7 @@ return this's cross-origin credentials.

  • Fire a progress event named progress at this with this's received bytes's length and - this's response's body's - total bytes. + length.

  • Let processEndOfBody be this step: run handle response end-of-body for @@ -968,8 +972,10 @@ return this's cross-origin credentials.

  • Let transmitted be xhr's received bytes's length. -

  • Let length be xhr's response's - body's total bytes. +

  • Let length be the result of extracting a length from + this's response's header list. + +

  • If length is not an integer, then set it to 0.

  • If xhr's synchronous flag is unset, then fire a progress event named progress at xhr with transmitted and