From cdd8cae6e1be977688355b8f1972f5495efcc775 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Thu, 25 Mar 2021 18:25:27 +0200 Subject: [PATCH 01/17] processResponseDone should receive a response Only call processResponseDone for responses that have their timing info set, which are responses that have passed CORS and redirects. Closes https://github.com/whatwg/fetch/issues/1201 --- fetch.bs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/fetch.bs b/fetch.bs index ce5814aef..d21062a10 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3512,7 +3512,7 @@ representing the number of bytes transmitted. If given, processRequestEndOf an algorithm accepting no arguments. If given, processResponse must be an algorithm accepting a response. If given, processResponseEndOfBody must be an algorithm accepting a response and null, failure, or a byte sequence. If -given, processResponseDone must be an algorithm accepting no arguments. +given, processResponseDone must be an algorithm accepting a response.

An ongoing fetch can be terminated with flag aborted, @@ -3982,13 +3982,21 @@ steps: response response, run these steps:

    +
  1. Let timingInfo be response's timing info. +

  2. Set fetchParams's request's done flag. +

  3. If timingInfo is null, then return. + +

  4. Set timingInfo's response end time to + the coarsened shared current time given fetchParams's + cross-origin isolated capability. +

  5. If fetchParams's process response done is not null, - then queue a fetch task given fetchParams's - process response done and fetchParams's - task destination. + then queue a fetch task to run fetchParams's + process response done given response, + with fetchParams's task destination.

To finalize and report timing given a response @@ -7269,8 +7277,9 @@ method steps are:

  • Terminate the ongoing fetch with the aborted flag set. -

  • Let handleFetchDone be to finalize and report timing with - response, globalObject, and "fetch". +

  • Let handleFetchDone given response response be to + finalize and report timing with response, globalObject, and + "fetch".

  • Fetch request with processResponseDone set to From 80884935e4a639541ae63f3626ae9ebeb4c4c7c8 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Thu, 25 Mar 2021 18:39:14 +0200 Subject: [PATCH 02/17] Nits --- fetch.bs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fetch.bs b/fetch.bs index d21062a10..767da15f0 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3988,8 +3988,8 @@ steps: done flag.

  • If timingInfo is null, then return. - -

  • Set timingInfo's response end time to + +

  • Set timingInfo's end time to the coarsened shared current time given fetchParams's cross-origin isolated capability. From 8e6950b8f74c8779f2c8525a458ee57759d18a10 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Sun, 28 Mar 2021 12:38:59 +0300 Subject: [PATCH 03/17] Assign fetch timing to response also for CORS failure Reset all metrics except for start/end time to zero. --- fetch.bs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/fetch.bs b/fetch.bs index 767da15f0..0efa791aa 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4289,9 +4289,20 @@ these steps:

  • If request's response tainting is "cors" and a - CORS check for request and response returns failure, then return a - network error. + CORS check for request and response returns failure, then: +

    As the CORS check is not to be applied to responses whose status is 304 or 407, or responses from a service worker for that matter, it is applied here. @@ -4348,9 +4359,8 @@ these steps:

    Attaching the timing info to a response is what makes it exposed to the web as a Resource Timing entry later. This step is done here, as resource-timing entries are available only - for HTTP fetches, including ones that are handled by service-workers or HTTP cache, and not for, - e.g., data:, blob: URL fetches, and are only available after all the - relevant security checks have succeeded. + for HTTP fetches, including ones that are handled by service-workers or HTTP cache, and not for + data: and blob: URL fetches.

  • Return response. Typically actualResponse's body's From a7399bf65c391fe9af74e43f6fc869e1b78e7cca Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Wed, 7 Apr 2021 18:19:23 +0300 Subject: [PATCH 04/17] Use real export from resource timing --- fetch.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index 0efa791aa..067f3c123 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4026,7 +4026,7 @@ steps:

  • Set response's timing info to timingInfo. -

  • Mark resource timing for +

  • Mark resource timing for timingInfo, originalURL, initiatorType, and global. From d128656fd8c6fe135629f543298573f15acfb79f Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 13 Apr 2021 19:06:05 +0300 Subject: [PATCH 05/17] Remove CORS part --- fetch.bs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/fetch.bs b/fetch.bs index 067f3c123..4163f1fd9 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4026,7 +4026,7 @@ steps:

  • Set response's timing info to timingInfo. -

  • Mark resource timing for +

  • Mark resource timing for timingInfo, originalURL, initiatorType, and global. @@ -4289,20 +4289,9 @@ these steps:

  • If request's response tainting is "cors" and a - CORS check for request and response returns failure, then: -

    As the CORS check is not to be applied to responses whose status is 304 or 407, or responses from a service worker for that matter, it is applied here. @@ -4359,8 +4348,9 @@ these steps:

    Attaching the timing info to a response is what makes it exposed to the web as a Resource Timing entry later. This step is done here, as resource-timing entries are available only - for HTTP fetches, including ones that are handled by service-workers or HTTP cache, and not for - data: and blob: URL fetches. + for HTTP fetches, including ones that are handled by service-workers or HTTP cache, and not for, + e.g., data:, blob: URL fetches, and are only available after all the + relevant security checks have succeeded.

  • Return response. Typically actualResponse's body's From 9f994a8ac5578f0f0bfed6acf714638d08df3e4a Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 13 Apr 2021 19:12:53 +0300 Subject: [PATCH 06/17] Send cache-state to resource timing --- fetch.bs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/fetch.bs b/fetch.bs index 4163f1fd9..40b589e25 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4011,13 +4011,20 @@ steps:

  • Let timingInfo be response's timing info. +

  • Let cacheState be response's cache state. +

  • If timingInfo is null, then return. -

  • If response's timing allow passed flag is not set, then set - timingInfo to a new fetch timing info whose - start time and - post-redirect start time are timingInfo's - start time. +

  • If response's timing allow passed flag is not set, then + perform the following steps: +

      +
    1. Set timingInfo to a new fetch timing info whose + start time and + post-redirect start time are timingInfo's + start time. + +

    2. Set cacheState to an empty string. +

  • Set timingInfo's end time to the coarsened shared current time given global's @@ -4027,7 +4034,8 @@ steps:

  • Set response's timing info to timingInfo.

  • Mark resource timing for - timingInfo, originalURL, initiatorType, and global. + timingInfo, originalURL, initiatorType, global and + cacheState. From 7a1c008e178de7c650b095822325c457bf6c2f24 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 13 Apr 2021 19:31:00 +0300 Subject: [PATCH 07/17] Use ref for now --- fetch.bs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fetch.bs b/fetch.bs index 40b589e25..7e307cf33 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4033,10 +4033,10 @@ steps:

  • Set response's timing info to timingInfo. -

  • Mark resource timing for - timingInfo, originalURL, initiatorType, global and +

  • + Mark resource timing + for timingInfo, originalURL, initiatorType, global and cacheState. - From 04d3a9b4197f3d42093c2888197459fa18955bb9 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Wed, 14 Apr 2021 14:05:21 +0300 Subject: [PATCH 08/17] Fix PR nits --- fetch.bs | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/fetch.bs b/fetch.bs index 7e307cf33..5771bc581 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3989,10 +3989,6 @@ steps:

  • If timingInfo is null, then return. -

  • Set timingInfo's end time to - the coarsened shared current time given fetchParams's - cross-origin isolated capability. -

  • If fetchParams's process response done is not null, then queue a fetch task to run fetchParams's process response done given response, @@ -4015,16 +4011,17 @@ steps:

  • If timingInfo is null, then return. -

  • If response's timing allow passed flag is not set, then - perform the following steps: -

      -
    1. Set timingInfo to a new fetch timing info whose - start time and - post-redirect start time are timingInfo's - start time. +

    2. +

      If response's timing allow passed flag is not set, then + perform the following steps: +

        +
      1. Set timingInfo to a new fetch timing info whose + start time and + post-redirect start time are timingInfo's + start time. -

      2. Set cacheState to an empty string. -

      +
    3. Set cacheState to an empty string. +

  • Set timingInfo's end time to the coarsened shared current time given global's @@ -4034,9 +4031,9 @@ steps:

  • Set response's timing info to timingInfo.

  • - Mark resource timing - for timingInfo, originalURL, initiatorType, global and - cacheState. + Mark resource timing + for timingInfo, originalURL, initiatorType, global, + and cacheState. @@ -7285,8 +7282,8 @@ method steps are:

  • Terminate the ongoing fetch with the aborted flag set. -

  • Let handleFetchDone given response response be to - finalize and report timing with response, globalObject, and +

  • Let handleFetchDone given response responseObject be to + finalize and report timing with responseObject, globalObject, and "fetch".

  • From 638862deb8ae1c771787ce710acbe9d4606ec18e Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Thu, 15 Apr 2021 13:35:45 +0300 Subject: [PATCH 09/17] More PR nits --- fetch.bs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/fetch.bs b/fetch.bs index 5771bc581..351f1b49f 100644 --- a/fetch.bs +++ b/fetch.bs @@ -3987,8 +3987,6 @@ steps:
  • Set fetchParams's request's done flag. -

  • If timingInfo is null, then return. -

  • If fetchParams's process response done is not null, then queue a fetch task to run fetchParams's process response done given response, @@ -4014,13 +4012,14 @@ steps:

  • If response's timing allow passed flag is not set, then perform the following steps: +

      -
    1. Set timingInfo to a new fetch timing info whose - start time and - post-redirect start time are timingInfo's - start time. +

    2. Set timingInfo to a new fetch timing info whose + start time and + post-redirect start time are timingInfo's + start time. -

    3. Set cacheState to an empty string. +

    4. Set cacheState to an empty string.

  • Set timingInfo's end time to the @@ -4030,10 +4029,9 @@ steps:

  • Set response's timing info to timingInfo. -

  • - Mark resource timing - for timingInfo, originalURL, initiatorType, global, - and cacheState. +

  • Mark resource timing for + timingInfo, originalURL, initiatorType, and global. + @@ -7282,7 +7280,7 @@ method steps are:

  • Terminate the ongoing fetch with the aborted flag set. -

  • Let handleFetchDone given response responseObject be to +

  • Let handleFetchDone given response response be to finalize and report timing with responseObject, globalObject, and "fetch". @@ -7295,16 +7293,16 @@ method steps are:

  • If locallyAborted is true, terminate these substeps.

  • If response's aborted flag is set, then abort fetch - with p, request, and responseObject, and terminate these + with p, request, and response, and terminate these substeps.

  • If response is a network error, then reject p with a {{TypeError}} and terminate these substeps. -

  • Set responseObject to the result of creating a {{Response}} +

  • Set response to the result of creating a {{Response}} object, given response, "immutable", and relevantRealm. -

  • Resolve p with responseObject. +

  • Resolve p with response.

  • Return p. From ab08fc0870051a89f926f29ef2fee9221a0bd579 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Thu, 15 Apr 2021 15:15:34 +0300 Subject: [PATCH 10/17] Undo unwanted responseObject changes --- fetch.bs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fetch.bs b/fetch.bs index 351f1b49f..7927b504a 100644 --- a/fetch.bs +++ b/fetch.bs @@ -7281,7 +7281,7 @@ method steps are:

  • Let handleFetchDone given response response be to - finalize and report timing with responseObject, globalObject, and + finalize and report timing with response, globalObject, and "fetch".

  • @@ -7293,16 +7293,16 @@ method steps are:
  • If locallyAborted is true, terminate these substeps.

  • If response's aborted flag is set, then abort fetch - with p, request, and response, and terminate these + with p, request, and responseObject, and terminate these substeps.

  • If response is a network error, then reject p with a {{TypeError}} and terminate these substeps. -

  • Set response to the result of creating a {{Response}} +

  • Set responseObject to the result of creating a {{Response}} object, given response, "immutable", and relevantRealm. -

  • Resolve p with response. +

  • Resolve p with responseObject.

  • Return p. From 9b79ae7ebe9915c6b65bc0416a53471b9e15796f Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 20 Apr 2021 14:13:43 +0300 Subject: [PATCH 11/17] More nits --- fetch.bs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/fetch.bs b/fetch.bs index 7927b504a..06e497604 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1932,10 +1932,6 @@ message as HTTP/2 does not support them. cache state (the empty string or "local"). Unlesss stated otherwise, it is the empty string. -

    This is intended solely for usage by service workers. [[SW]] - -

    A response has an associated CSP list, which is a list of Content Security Policy objects for the response. The list is empty unless @@ -3982,8 +3978,6 @@ steps: response response, run these steps:

      -
    1. Let timingInfo be response's timing info. -

    2. Set fetchParams's request's done flag. From 2f668b653c9640b67f88a163e764c936dbe101eb Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 20 Apr 2021 15:27:18 +0300 Subject: [PATCH 12/17] Amend --- fetch.bs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index 06e497604..2687bb67b 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4024,7 +4024,8 @@ steps:

    3. Set response's timing info to timingInfo.

    4. Mark resource timing for - timingInfo, originalURL, initiatorType, and global. + timingInfo, originalURL, initiatorType, global, and + cacheState.

    From cef771da01b19833fb4c9e306b0216f59b032859 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 20 Apr 2021 17:34:08 +0300 Subject: [PATCH 13/17] nits --- fetch.bs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fetch.bs b/fetch.bs index 2687bb67b..91ce1fbf7 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1932,6 +1932,9 @@ message as HTTP/2 does not support them. cache state (the empty string or "local"). Unlesss stated otherwise, it is the empty string. +

    This is intended for usage by Service Workers and +Resource Timing. [[SW]] +

    A response has an associated CSP list, which is a list of Content Security Policy objects for the response. The list is empty unless From e61e0a83d10faf11f04a211c86aaa81650a82802 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Tue, 20 Apr 2021 17:36:07 +0300 Subject: [PATCH 14/17] Update note --- fetch.bs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fetch.bs b/fetch.bs index 91ce1fbf7..ff9bcc363 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1933,7 +1933,9 @@ message as HTTP/2 does not support them. "local"). Unlesss stated otherwise, it is the empty string.

    This is intended for usage by Service Workers and -Resource Timing. [[SW]] +Resource Timing. [[SW]] [[RESOURCE-TIMING]] +

    A response has an associated CSP list, which is a list From 51dd0e303151ab6e5b81240caf57e4cd63e71aa3 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Wed, 21 Apr 2021 13:34:48 +0300 Subject: [PATCH 15/17] Use real ref for mark --- fetch.bs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fetch.bs b/fetch.bs index ff9bcc363..be76be86b 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4028,10 +4028,9 @@ steps:

  • Set response's timing info to timingInfo. -

  • Mark resource timing for +

  • Mark resource timing for timingInfo, originalURL, initiatorType, global, and cacheState. - From 764e995c059b898f14c329d620a1c3ce495bb8aa Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Wed, 21 Apr 2021 13:40:06 +0300 Subject: [PATCH 16/17] Fix line length --- fetch.bs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fetch.bs b/fetch.bs index be76be86b..f8e12f858 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4028,9 +4028,8 @@ steps:

  • Set response's timing info to timingInfo. -

  • Mark resource timing for - timingInfo, originalURL, initiatorType, global, and - cacheState. +

  • Mark resource timing for timingInfo, originalURL, + initiatorType, global, and cacheState. From b455c911e9e08fdd24861cc24375822e8d488e93 Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Wed, 21 Apr 2021 12:56:49 +0200 Subject: [PATCH 17/17] nits --- fetch.bs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fetch.bs b/fetch.bs index f8e12f858..30dceaceb 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4009,8 +4009,7 @@ steps:

  • If timingInfo is null, then return.

  • -

    If response's timing allow passed flag is not set, then - perform the following steps: +

    If response's timing allow passed flag is not set, then:

    1. Set timingInfo to a new fetch timing info whose @@ -4018,7 +4017,7 @@ steps: post-redirect start time are timingInfo's start time. -

    2. Set cacheState to an empty string. +

    3. Set cacheState to the empty string.

  • Set timingInfo's end time to the