From 7651857020510d82e6e788bbc43d32b0b2b3cf3f Mon Sep 17 00:00:00 2001 From: Noam Rosenthal Date: Mon, 8 Nov 2021 14:27:19 +0200 Subject: [PATCH] Specify how "terminate" works In conjunction with https://github.com/whatwg/fetch/pull/1329. When the SW fetch starts, it emits an `onStart` callback with a controller instance. That controller instance can be used to terminate the service worker fetch and it's internal fetches. --- docs/index.bs | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/index.bs b/docs/index.bs index 9e1f5ee4..ffd1e216 100644 --- a/docs/index.bs +++ b/docs/index.bs @@ -2975,6 +2975,35 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 1. Set |serviceWorker|'s [=start status=] to null. +
+ A service worker fetch controller is a [=/struct=]. It has the following [=struct/items=]: + +
+ : state (default "ongoing") + :: "ongoing" or "terminated". + + : preload fetch controller (default null) + :: Null or a [=fetch controller=] +
+
+ +
+ + The terminate Service-Worker Fetch algorithm enables terminating an ongoing [=handle fetch=] process. + + : Input + :: |controller|, a [=service worker fetch controller=] + : Output + :: None + + 1. Set |controller|'s [=service worker fetch controller/state=] to "terminated". + 1. If |controller|'s [=service worker fetch controller/preload fetch controller=] is not null, [=fetch controller/abort=] |controller|'s [=service worker fetch controller/preload fetch controller=]. +
+ + given a [=service worker fetch controller=] |controller|: + + +

Handle Fetch

@@ -2983,10 +3012,12 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 : Input :: |request|, a [=/request=] :: |useHighResPerformanceTimers|, a boolean + :: |onStarted|, an algorithm accepting a [=service worker fetch controller=] : Output :: |response|, a [=/response=] 1. Let |handleFetchFailed| be false. + 1. Let |controller| be a new [=service worker fetch controller=]. 1. Let |respondWithEntered| be false. 1. Let |eventCanceled| be false. 1. Let |response| be null. @@ -2997,7 +3028,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231 1. Let |workerRealm| be null. 1. Let |eventHandled| be null. 1. Let |timingInfo| be a new [=service worker timing info=]. - 1. Let |fetchInstance| be the instance of the [=/fetch=] algorithm representing the ongoing fetch. + 1. Call |onFetchStarted| with |controller|. 1. Assert: |request|'s [=request/destination=] is not "serviceworker". 1. If |request|'s [=request/destination=] is either "embed" or "object", then: 1. Return null. @@ -3023,14 +3054,11 @@ 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. Run the following substeps [=in parallel=]: - 1. [=Fetch=] |preloadRequest| and let |preloadFetchInstance| be the instance of the [=/fetch=] algorithm. - + 1. [=Fetch=] |preloadRequest|, with [=fetch/processFetchStart=] given [=fetch controller=] |internalFetchController| be to set |controller|'s [=service worker fetch controller/preload fetch controller=] to |internalFetchController|. 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. 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 +3104,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|'s [=service worker controller/state=] is "terminated", then [=queue a task=] to [=AbortSignal/signal abort=] on |requestObject|'s {{Request/signal}}. If |task| is discarded, set |handleFetchFailed| to true.