diff --git a/fetch.bs b/fetch.bs index 44548a758..41cb5141d 100644 --- a/fetch.bs +++ b/fetch.bs @@ -2950,9 +2950,10 @@ and a response response, is to run these steps: false. -
  • Wait for 1024 bytes of response's body or end-of-file, - whichever comes first and let bytes be those bytes. - +

  • Let bytes be the result of running + obtain a copy of the first 1024 bytes of response given response. + +

  • If bytes is failure, then return false.

  • If the audio or video type pattern matching algorithm given bytes does not @@ -2990,6 +2991,79 @@ and a response response, is to run these steps:

  • If mimeType's essence starts with "audio/", "image/", or "video/", then return false. +

  • Return determine if response is JavaScript and not JSON given response. + + +


    + +

    To obtain a copy of the first 1024 bytes of response, given a response +response, run these steps: + +

      +
    1. Let first1024Bytes be null. + +

    2. +

      In parallel: + +

        +
      1. Let bytes be the empty byte sequence. + +

      2. Let transformStream be a new {{TransformStream}}. + +

      3. +

        Let transformAlgorithm given a chunk be these steps: + +

          +
        1. Enqueue chunk in transformStream. + +

        2. +

          If first1024Bytes is null, then: + +

            +
          1. Let chunkBytes be + a copy of the bytes held by + chunk. + +

          2. Append chunkBytes to bytes. + +

          3. +

            If bytes's length is greater than 1024, then: + +

              +
            1. Truncate bytes from the end so that it only contains 1024 bytes. + +

            2. Set first1024Bytes to bytes. +

            +
          +
        + +
      4. Let flushAlgorithm be this step: if first1024Bytes is null, then set + first1024Bytes to bytes. + +

      5. Set up transformStream with + transformAlgorithm set to + transformAlgorithm and flushAlgorithm set + to flushAlgorithm. + +

      6. Set response's body's stream to the result + of response's body's stream + piped through transformStream. +

      + +
    3. Wait until first1024Bytes is non-null or response's + body's stream is errored. + +

    4. If first1024Bytes is null, then return failure. + +

    5. Return first1024Bytes. +
    + +
    + +

    To determine if response is JavaScript and not JSON given a response +response, run these steps:

    + +
    1. Let responseBodyBytes be null.

    2. @@ -3013,8 +3087,11 @@ and a response response, is to run these steps:
    3. Assert: responseBodyBytes is a byte sequence. -

    4. If parse JSON bytes to a JavaScript value given responseBodyBytes does not - throw, then return false. If it throws, catch the exception and ignore it. +

    5. +

      If parse JSON bytes to a JavaScript value given responseBodyBytes does not + throw, then return false. If it throws, catch the exception and ignore it. + +

      If there is an exception, response is not JSON. If there is not, it is.

    6. Let sourceText be the result of decoding responseBodyBytes given request's