diff --git a/fetch.bs b/fetch.bs index afa26221d..2d9713621 100644 --- a/fetch.bs +++ b/fetch.bs @@ -210,10 +210,38 @@ lt="authentication entry">authentication entries (for HTTP authentication).
cross-origin isolated capability (default false)
A boolean. +
controller (default a new fetch controller) +
A fetch controller. +
timing info
A fetch timing info. +

A fetch controller is a struct used to enable callers of +fetch to perform certain operations on it after it has started. It has the following +items: + +

+
state (default "ongoing") +
"ongoing", "terminated", or "aborted" +
+ +

To abort a fetch controller +controller, set controller's state to +"aborted". + +

To terminate a fetch controller +controller, set controller's state to +"terminated". + +

A fetch params fetchParams is aborted if +its controller's state is +"aborted". + +

A fetch params fetchParams is canceled if +its controller's state is +"aborted" or "terminated". +

A fetch timing info is a struct used to maintain timing information needed by Resource Timing and Navigation Timing. It has the following items: [[RESOURCE-TIMING]] [[NAVIGATION-TIMING]] @@ -2104,6 +2132,16 @@ known as an aborted network errorheader list is always empty, and body is always null. +

To create the appropriate network error given fetch params +fetchParams: + +

    +
  1. Assert: fetchParams is canceled. + +

  2. Return an aborted network error if fetchParams is + aborted; otherwise return a network error. +

+

A filtered response is a limited view on a @@ -2285,16 +2323,18 @@ functionality. request).

A fetch record has an associated -fetch (a -fetch algorithm or null). +controller (a +fetch controller or null).


When a fetch group is terminated, for each associated -fetch record whose request's done flag is -unset or keepalive is false, terminate the -fetch record's fetch. +fetch record whose fetch record's +controller is not null, and whose request's +done flag is unset or keepalive is false, +terminate the fetch record's +controller.

Resolving domains

@@ -3757,10 +3797,6 @@ an integer representing the number of bytes transmitted. If given, given, processResponseConsumeBody must be an algorithm accepting a response and null, failure, or a byte sequence. -

An ongoing fetch can be -terminated with flag aborted, -which is unset unless otherwise specified. -

The user agent may be asked to suspend the ongoing fetch. The user agent may either accept or ignore the suspension request. The suspended fetch can be @@ -3889,14 +3925,17 @@ the request.

If request is a subresource request, then:

    -
  1. Let record be a new fetch record consisting of - request and this instance of the fetch algorithm. +

  2. Let record be a new fetch record whose + request is request and controller + is fetchParams's controller.

  3. Append record to request's client's fetch group list of fetch records.

  • Run main fetch given fetchParams. + +

  • Return fetchParams's controller. @@ -4354,7 +4393,8 @@ steps:

    1. -

      Run these steps, but abort when the ongoing fetch is terminated: +

      Run these steps, but abort when fetchParams is + canceled:

      1. Let blob be request's current URL's @@ -4385,16 +4425,8 @@ steps:

      2. Return response.

      -
    2. -

      If aborted, then: - -

        -
      1. Let aborted be the termination's aborted flag. - -

      2. If aborted is set, then return an aborted network error. - -

      3. Return a network error. -

      +
    3. If aborted, then return the appropriate network error for + fetchParams.

    "data" @@ -4461,10 +4493,12 @@ these steps:

    Let transformAlgorithm given chunk be these steps:

      -
    1. If the ongoing fetch is terminated, then abort these steps. +

    2. If fetchParams is canceled, then abort these + steps.

    3. If chunk is not a {{Uint8Array}} object, then - terminate the ongoing fetch. + terminate fetchParams's + controller.

    4. Otherwise, enqueue chunk. The user agent may split the chunk into implementation-defined practical sizes and @@ -4488,7 +4522,9 @@ these steps: given fetchParams's cross-origin isolated capability.

    5. Set response to the result of invoking handle fetch for - requestForServiceWorker. [[!HTML]] [[!SW]] + requestForServiceWorker, with fetchParams's + controller and fetchParams's + cross-origin isolated capability. [[!HTML]] [[!SW]]

    6. If response is not null, then: @@ -4793,7 +4829,8 @@ steps. They return a response.

    7. Let the revalidatingFlag be unset.

    8. -

      Run these steps, but abort when the ongoing fetch is terminated: +

      Run these steps, but abort when fetchParams is + canceled:

      1. If request's window is "no-window" and @@ -5127,16 +5164,9 @@ steps. They return a response.

    -
  • -

    If aborted, then: - -

      -
    1. Let aborted be the termination's aborted flag. - -

    2. If aborted is set, then return an aborted network error. +

    3. If aborted, then return the appropriate network error for + fetchParams. -

    4. Return a network error. -

  • @@ -5232,16 +5262,8 @@ steps. They return a response. isAuthenticationFetch is true, then:
      -
    1. -

      If the ongoing fetch is terminated, then: - -

        -
      1. Let aborted be the termination's aborted flag. - -

      2. If aborted is set, then return an aborted network error. - -

      3. Return a network error. -

      +
    2. If fetchParams is canceled, then return the + appropriate network error for fetchParams.

    3. Let username and password be the result of prompting the end user for a username and password, respectively, in request's @@ -5268,16 +5290,8 @@ steps. They return a response.

    4. Needs testing: multiple `Proxy-Authenticate` headers, missing, parsing issues. -

    5. -

      If the ongoing fetch is terminated, then: - -

        -
      1. Let aborted be the termination's aborted flag. - -

      2. If aborted is set, then return an aborted network error. - -

      3. Return a network error. -

      +
    6. If fetchParams is canceled, then return the + appropriate network error for fetchParams.

    7. Prompt the end user as appropriate in request's @@ -5306,16 +5320,8 @@ steps. They return a response.

      then:

        -
      1. -

        If the ongoing fetch is terminated, then: - -

          -
        1. Let aborted be the termination's aborted flag. - -

        2. If aborted is set, then return an aborted network error. - -

        3. Return a network error. -

        +
      2. If fetchParams is canceled, then return the + appropriate network error for fetchParams.

      3. Set response to the result of running HTTP-network-or-cache fetch given fetchParams, isAuthenticationFetch, and true. @@ -5372,7 +5378,8 @@ optional boolean forceNewConnection (default false), run these steps:

      4. -

        Run these steps, but abort when the ongoing fetch is terminated: +

        Run these steps, but abort when fetchParams is + canceled:

        1. If connection is failure, then return a network error. @@ -5474,7 +5481,8 @@ optional boolean forceNewConnection (default false), run these steps:

          Let processBodyChunk given bytes be these steps:

            -
          1. If the ongoing fetch is terminated, then abort these steps. +

          2. If fetchParams is canceled, then abort these + steps.

          3. Run this step in parallel: transmit bytes. @@ -5488,7 +5496,8 @@ optional boolean forceNewConnection (default false), run these steps:

            Let processEndOfBody be these steps:

              -
            1. If the ongoing fetch is terminated, then abort these steps. +

            2. If fetchParams is canceled, then abort these + steps.

            3. If fetchParams's process request end-of-body is non-null, then run fetchParams's @@ -5499,12 +5508,15 @@ optional boolean forceNewConnection (default false), run these steps:

              Let processBodyError given e be these steps:

                -
              1. If the ongoing fetch is terminated, then abort these steps. +

              2. If fetchParams is canceled, then abort these + steps.

              3. If e is an "AbortError" {{DOMException}}, - then terminate the ongoing fetch with the aborted flag set. + then abort fetchParams's + controller. -

              4. Otherwise, terminate the ongoing fetch. +

              5. Otherwise, terminate fetchParams's + controller.

            4. Incrementally read request's body given @@ -5521,20 +5533,16 @@ optional boolean forceNewConnection (default false), run these steps:

              If aborted, then:

                -
              1. Let aborted be the termination's aborted flag. -

              2. If connection uses HTTP/2, then transmit an RST_STREAM frame. -

              3. If aborted is set, then return an aborted network error. - -

              4. Return a network error. +

              5. Return the appropriate network error for fetchParams.

              -
            5. Let pullAlgorithm be an action that resumes the +

            6. Let pullAlgorithm be an algorithm that resumes the ongoing fetch if it is suspended. -

            7. Let cancelAlgorithm be an action that terminates - the ongoing fetch with the aborted flag set. +

            8. Let cancelAlgorithm be an algorithm that aborts + fetchParams's controller.

            9. Let highWaterMark be a non-negative, non-NaN number, chosen by the user agent. @@ -5550,7 +5558,8 @@ optional boolean forceNewConnection (default false), run these steps: sizeAlgorithm set to sizeAlgorithm.

            10. -

              Run these steps, but abort when the ongoing fetch is terminated: +

              Run these steps, but abort when fetchParams is + canceled:

              1. Set response's body to a new @@ -5579,10 +5588,8 @@ optional boolean forceNewConnection (default false), run these steps:

                If aborted, then:

                  -
                1. Let aborted be the termination's aborted flag. - -

                2. If aborted is set, then set response's - aborted flag. +

                3. If fetchParams is aborted, then set + response's aborted flag.

                4. Return response.

                @@ -5592,7 +5599,8 @@ optional boolean forceNewConnection (default false), run these steps:
                1. -

                  Run these steps, but abort when the ongoing fetch is terminated: +

                  Run these steps, but abort when fetchParams is + canceled:

                  1. @@ -5621,14 +5629,15 @@ optional boolean forceNewConnection (default false), run these steps:
                  2. Increase timingInfo's decoded body size by bytes's length. -

                  3. If bytes is failure, then terminate the - ongoing fetch. +

                  4. If bytes is failure, then terminate + fetchParams's controller.

                  5. Enqueue a {{Uint8Array}} wrapping an {{ArrayBuffer}} containing bytes into stream.

                  6. If stream is errored, then - terminate the ongoing fetch. + terminate fetchParams.'s + controller.

                  7. If stream doesn't need more data ask the user agent to suspend the ongoing fetch. @@ -5644,10 +5653,9 @@ optional boolean forceNewConnection (default false), run these steps:

                    If aborted, then:

                      -
                    1. Let aborted be the termination's aborted flag.

                    2. -

                      If aborted is set, then: +

                      If fetchParams is aborted, then:

                      1. Set response's aborted flag. @@ -7573,6 +7581,8 @@ method steps are:

                        This lets us reject promises with predictable timing, when the request to abort comes from the same thread as the call to fetch. +

                      2. Let controller be null. +

                      3. Add the following abort steps to requestObject's signal: @@ -7582,7 +7592,8 @@ method steps are:

                      4. Abort fetch with p, request, and responseObject. -

                      5. Terminate the ongoing fetch with the aborted flag set. +

                      6. If controller is not null, then abort + controller.

                    3. Let handleFetchDone given response response be to @@ -7590,7 +7601,8 @@ method steps are: "fetch".

                    4. -

                      Fetch request with processResponseEndOfBody set to +

                      Set controller to the result of calling fetch given + request, with processResponseEndOfBody set to handleFetchDone, and processResponse given response being these substeps: @@ -7640,7 +7652,7 @@ method steps are:

                      Garbage collection

                      -

                      The user agent may terminate an ongoing fetch if that termination +

                      The user agent may terminate an ongoing fetch if that termination is not observable through script.

                      "Observable through script" means observable through @@ -8006,6 +8018,7 @@ resource — for non-CORS requests as well as CORS requests — and do not use `Vary`. +

                      Using fetch in other standards

                      In its essence fetching is an exchange of a request for a @@ -8074,6 +8087,12 @@ in a parallel queue if useParallelQueue is as arguments will be invoked. Hopefully most standards will not need this. +

                      When invoked, the fetch operation returns a fetch controller. The +controller is used for performing actions on a fetch operation that has already started, such as +aborting the operation by the user or page logic, or +terminating it due to a browser-internal circumstance. + +

                      Acknowledgments