Skip to content

Commit

Permalink
Specify how "terminate" works
Browse files Browse the repository at this point in the history
In conjunction with whatwg/fetch#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.
  • Loading branch information
noamr committed Nov 8, 2021
1 parent 5b99fff commit ec9979c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions docs/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2989,7 +2989,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231

<section algorithm>

The <dfn export>Terminate Service-Worker Fetch</dfn> algorithm enables terminating an ongoing [=handle fetch=] process.
The <dfn export>terminate Service-Worker Fetch</dfn> algorithm enables terminating an ongoing [=handle fetch=] process.

: Input
:: |controller|, a [=service worker fetch controller=]
Expand All @@ -3012,9 +3012,9 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
: Input
:: |request|, a [=/request=]
:: |useHighResPerformanceTimers|, a boolean
:: |handleResponse|, an algorithm accepting Null or a [=/response=]
:: |onStarted|, an algorithm accepting a [=service worker fetch controller=]
: Output
:: |controller| a [=service worker controller=]
:: |response|, a [=/response=]

1. Let |handleFetchFailed| be false.
1. Let |controller| be a new [=service worker fetch controller=].
Expand All @@ -3028,21 +3028,21 @@ 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. Call |onFetchStarted| with |controller|.
1. Assert: |request|'s [=request/destination=] is not "<code>serviceworker</code>".
1. Return |controller| and run the remaining steps [=in parallel=], but [=abort when=] |controller|'s [=service worker fetch controller/state=] is "<code>terminated</code>".
1. If |request|'s [=request/destination=] is either "<code>embed</code>" or "<code>object</code>", then:
1. Call |handleResponse| with null.
1. Return null.
1. Else if |request| is a <a>non-subresource request</a>, then:

Note: If the non-subresource request is under the scope of a service worker registration, application cache is completely bypassed regardless of whether the non-subresource request uses the service worker registration.

1. If |reservedClient| is not null and is an <a>environment settings object</a>, then:
1. If |reservedClient| is not a <a>secure context</a>, call |handleResponse| with null and return.
1. If |reservedClient| is not a <a>secure context</a>, return null.
1. Else:
1. If |request|'s [=request/url=] is not a <a>potentially trustworthy URL</a>, call |handleResponse| with null and return.
1. If |request|'s [=request/url=] is not a <a>potentially trustworthy URL</a>, return null.
1. If |request| is a <a>navigation request</a> and the <a lt="navigate">navigation</a> triggering it was initiated with a shift+reload or equivalent, return null.
1. Set |registration| to the result of running <a>Match Service Worker Registration</a> algorithm passing |request|'s [=request/url=] as the argument.
1. If |registration| is null or |registration|'s <a>active worker</a> is null, call |handleResponse| with null and return..
1. If |registration| is null or |registration|'s <a>active worker</a> is null, return null.
1. If |request|'s [=request/destination=] is not {{RequestDestination/"report"}}, set |reservedClient|'s <a>active service worker</a> to |registration|'s <a>active worker</a>.
1. If |request| is a [=navigation request=], |registration|'s [=navigation preload enabled flag=] is set, |request|'s [=request/method=] is \`<code>GET</code>\`, and |registration|'s [=active worker=]'s <a>set of event types to handle</a> [=set/contains=] <code>fetch</code>, then:

Expand All @@ -3054,7 +3054,7 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
1. [=header list/Append=] to |preloadRequestHeaders| a new [=header=] whose [=header/name=] is \`<code>Service-Worker-Navigation-Preload</code>\` 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. Set |controller|'s [=service worker fetch controller/preload fetch controller=] to the result of invoking [=fetch=] with |preloadRequest|.
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|.
Expand All @@ -3065,14 +3065,14 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231

1. Else if |request| is a <a>subresource request</a>, then:
1. If |client|'s <a>active service worker</a> is non-null, set |registration| to |client|'s <a>active service worker</a>'s <a>containing service worker registration</a>.
1. Else, call |handleResponse| with null and return.
1. Else, return null.
1. Let |activeWorker| be |registration|'s <a>active worker</a>.
1. Let |shouldSoftUpdate| be true if any of the following are true, and false otherwise:
* |request| is a [=non-subresource request=].
* |request| is a [=subresource request=] and |registration| is [=stale=].
1. If the result of running the [=Should Skip Event=] algorithm with "fetch" and |activeWorker| is true, then:
1. If |shouldSoftUpdate| is true, then [=in parallel=] run the [=Soft Update=] algorithm with |registration|.
1. Call |handleResponse| with null and return.
1. Return null.
1. If |useHighResPerformanceTimers| is true, then set |useHighResPerformanceTimers| to |activeWorker|'s [=service worker/global object=]'s [=WorkerGlobalScope/cross-origin isolated capability=].
1. Let |timingInfo|'s [=service worker timing info/start time=] be the [=coarsened shared current time=] given |useHighResPerformanceTimers|.
1. If |activeWorker|'s <a>state</a> is "`activating`", wait for |activeWorker|'s <a>state</a> to become "`activated`".
Expand Down Expand Up @@ -3115,14 +3115,14 @@ spec: rfc7231; urlPrefix: https://tools.ietf.org/html/rfc7231
1. If |respondWithEntered| is false, then:
1. If |eventCanceled| is true, then:
1. If |eventHandled| is not null, then [=reject=] |eventHandled| with a "{{NetworkError}}" {{DOMException}} in |workerRealm|.
2. Call |handleResponse| with a [=network error=] and return.
2. Return a [=network error=].
1. If |eventHandled| is not null, then [=resolve=] |eventHandled|.
1. Call |handleResponse| with null and return.
1. Return null.
1. If |handleFetchFailed| is true, then:
1. If |eventHandled| is not null, then [=reject=] |eventHandled| with a "{{NetworkError}}" {{DOMException}} in |workerRealm|.
2. Call |handleResponse| with a [=network error=] and return.
2. Return a [=network error=].
1. If |eventHandled| is not null, then [=resolve=] |eventHandled|.
1. Call |handleResponse| with |response|.
1. Return |response|.
</section>

<section algorithm>
Expand Down

0 comments on commit ec9979c

Please sign in to comment.