From 2c1ae24b7018288140c3c0b2119848eb916d381d Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Fri, 19 Nov 2021 15:02:03 +0200 Subject: [PATCH 1/4] Pass controller from fetch, and abort SW fetch when it's canceled --- docs/index.bs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/index.bs b/docs/index.bs index 9e1f5ee4..20144d67 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -2981,6 +2981,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 The [=Handle Fetch=] algorithm is the entry point for the [=/fetch=] handling handed to the [=/service worker=] context. : Input + :: |controller|, a [=fetch controller=] :: |request|, a [=/request=] :: |useHighResPerformanceTimers|, a boolean : Output @@ -3022,15 +3023,16 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 1. Let |preloadResponseObject| be a new {{Response}} object associated with a new {{Headers}} object whose [=guard=] is "`immutable`". 1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is \`Service-Worker-Navigation-Preload\` and [=header/value=] is |registration|'s [=navigation preload header value=]. 1. Set |preloadRequest|'s [=service-workers mode=] to "`none`". - 1. Run the following substeps [=in parallel=]: - 1. [=Fetch=] |preloadRequest| and let |preloadFetchInstance| be the instance of the [=/fetch=] algorithm. + 1. Let |preloadFetchController| be null. + 1. Run the following substeps [=in parallel=], but [=abort when=] |controller| is [=fetch controller/cancelled]: + 1. Set |preloadFetchController| to the result of [=Fetch|fetching=] |preloadRequest|. To [=process response=] for |navigationPreloadResponse|, run these substeps: 1. If |navigationPreloadResponse|'s [=response/type=] is "`error`", reject |preloadResponse| with a `TypeError` and terminate these substeps. 1. Associate |preloadResponseObject| with |navigationPreloadResponse|. 1. Resolve |preloadResponse| with |preloadResponseObject|. - 1. If |fetchInstance| is [=fetch/terminated=], then [=fetch/terminate=] |preloadFetchInstance| with the aborted flag set. + 1. [=If aborted=], then [=fetch controller/abort=] |preloadFetchController|. 1. Else, resolve |preloadResponse| with undefined. Note: From this point, the [=/service worker client=] starts to use its active service worker's containing service worker registration. @@ -3076,7 +3078,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 1. Else, [=ReadableStream/cancel=] |request|'s [=request/body=] with undefined. 1. If |response| is not null, then set |response|'s [=response/service worker timing info=] to |timingInfo|. 1. If |e|'s canceled flag is set, set |eventCanceled| to true. - 1. If |fetchInstance| is [=fetch/terminated=], then [=queue a task=] to [=AbortSignal/signal abort=] on |requestObject|'s {{Request/signal}}. + 1. If |controller| is [=fetch controller/cancelled=], then [=queue a task=] to [=AbortSignal/signal abort=] on |requestObject|'s {{Request/signal}}. If |task| is discarded, set |handleFetchFailed| to true. From 0ccf56bd3e021f413e9bd4403c737ce5e61fc3ab Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Fri, 19 Nov 2021 16:11:20 +0200 Subject: [PATCH 2/4] Switch argument order --- docs/index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.bs b/docs/index.bs index 20144d67..e47c6b3c 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -2981,8 +2981,8 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 The [=Handle Fetch=] algorithm is the entry point for the [=/fetch=] handling handed to the [=/service worker=] context. : Input - :: |controller|, a [=fetch controller=] :: |request|, a [=/request=] + :: |controller|, a [=fetch controller=] :: |useHighResPerformanceTimers|, a boolean : Output :: |response|, a [=/response=] From 0ec9f0317471316f19f0d0342e23e4df77a44b44 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Fri, 19 Nov 2021 16:13:33 +0200 Subject: [PATCH 3/4] nits --- docs/index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.bs b/docs/index.bs index e47c6b3c..0a53ba80 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -3024,7 +3024,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is \`Service-Worker-Navigation-Preload\` and [=header/value=] is |registration|'s [=navigation preload header value=]. 1. Set |preloadRequest|'s [=service-workers mode=] to "`none`". 1. Let |preloadFetchController| be null. - 1. Run the following substeps [=in parallel=], but [=abort when=] |controller| is [=fetch controller/cancelled]: + 1. Run the following substeps [=in parallel=], but [=abort when=] |controller|'s [=fetch controller/state=] is "terminated" or "aborted": 1. Set |preloadFetchController| to the result of [=Fetch|fetching=] |preloadRequest|. To [=process response=] for |navigationPreloadResponse|, run these substeps: From ac0ba3ae26113f3f7d3d2eeb86e319f7d4ded1c4 Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Fri, 19 Nov 2021 16:14:20 +0200 Subject: [PATCH 4/4] nits --- docs/index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.bs b/docs/index.bs index 0a53ba80..33d01b23 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -3078,7 +3078,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 1. Else, [=ReadableStream/cancel=] |request|'s [=request/body=] with undefined. 1. If |response| is not null, then set |response|'s [=response/service worker timing info=] to |timingInfo|. 1. If |e|'s canceled flag is set, set |eventCanceled| to true. - 1. If |controller| is [=fetch controller/cancelled=], then [=queue a task=] to [=AbortSignal/signal abort=] on |requestObject|'s {{Request/signal}}. + 1. If |controller| [=fetch controller/state=] is "terminated" or "aborted", then [=queue a task=] to [=AbortSignal/signal abort=] on |requestObject|'s {{Request/signal}}. If |task| is discarded, set |handleFetchFailed| to true.