From 0a3de95d0731e6430ba5ebf9bc53bab489ee32ae Mon Sep 17 00:00:00 2001 From: Anne van Kesteren Date: Tue, 20 Jul 2021 13:01:10 +0200 Subject: [PATCH] Use tasks to manipulate streams Helps with #1246. The main problem with this PR (which is why I marked it WIP) is that the stream itself is created in parallel and I don't see a good way to avoid that. If we had low-level streams this would be different. --- fetch.bs | 94 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/fetch.bs b/fetch.bs index 5ac06793e..47d35a91a 100644 --- a/fetch.bs +++ b/fetch.bs @@ -4199,9 +4199,7 @@ steps:

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 the termination's aborted flag is set, then return an aborted network error.

  4. Return a network error.

@@ -4937,9 +4935,7 @@ 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 the termination's aborted flag is set, then return an aborted network error.

  4. Return a network error.

@@ -5039,9 +5035,7 @@ steps. They return a response.

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. If the termination's aborted flag is set, then return an aborted network error.

  4. Return a network error.

@@ -5075,9 +5069,7 @@ steps. They return a response.

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. If the termination's aborted flag is set, then return an aborted network error.

  4. Return a network error.

@@ -5113,9 +5105,7 @@ steps. They return a response.

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. If the termination's aborted flag is set, then return an aborted network error.

  4. Return a network error.

@@ -5320,11 +5310,9 @@ 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. If the termination's aborted flag is set, then return an aborted network error.

  5. Return a network error.

@@ -5378,9 +5366,7 @@ 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 +

  3. If the termination's aborted flag is set, then set response's aborted flag.

  4. Return response. @@ -5423,20 +5409,28 @@ optional boolean forceNewConnection (default false), run these steps:

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

  6. Enqueue a {{Uint8Array}} wrapping an {{ArrayBuffer}} - containing bytes into stream. +

  7. +

    Let handleResponseBytes be these steps: -

  8. If stream is errored, then - terminate the ongoing fetch. +

      +
    1. Enqueue a {{Uint8Array}} wrapping an {{ArrayBuffer}} + containing bytes into stream. -

    2. If stream doesn't need more data ask the user - agent to suspend the ongoing fetch. +

    3. If stream is errored, then + terminate the ongoing fetch. + +

    4. If stream doesn't need more data ask the user + agent to suspend the ongoing fetch. +

    + +
  9. Otherwise, if the bytes transmission for response's message body is done + normally and stream is readable, then + close stream, finalize response for + fetchParams and response.

-
  • Otherwise, if the bytes transmission for response's message body is done - normally and stream is readable, then - close stream, finalize response for - fetchParams and response, and abort these in-parallel steps. +

  • Queue a fetch task given handleResponseBytes and + fetchParams's task destination. @@ -5446,22 +5440,6 @@ optional boolean forceNewConnection (default false), run these steps:

    1. Finalize response for fetchParams and response. -
    2. Let aborted be the termination's aborted flag. - -

    3. -

      If aborted is set, then: - -

        -
      1. Set response's aborted flag. - -

      2. If stream is readable, - error stream with an - "AbortError" {{DOMException}}. -

      - -
    4. Otherwise, if stream is readable, - error stream with a {{TypeError}}. -

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

    6. @@ -5471,6 +5449,28 @@ optional boolean forceNewConnection (default false), run these steps:

      For instance, the user agent could keep the connection open if it knows there's only a few bytes of transfer remaining on a reusable connection. In this case it could be worse to close the connection and go through the handshake process again for the next fetch. + +

    7. +

      Let handleResponseError be these steps: + +

        +
      1. +

        If the termination's aborted flag is set, then: + +

          +
        1. Set response's aborted flag. + +

        2. If stream is readable, + error stream with an + "AbortError" {{DOMException}}. +

        + +
      2. Otherwise, if stream is readable, + error stream with a {{TypeError}}. +

      + +
    8. Queue a fetch task given handleResponseError and + fetchParams's task destination.