diff --git a/fetch.bs b/fetch.bs index a317c5166..b836c9fda 100644 --- a/fetch.bs +++ b/fetch.bs @@ -1090,11 +1090,12 @@ outlawing forbidden methods and forbidden header names.

A request has an associated -body (null or a +body (null, a byte sequence, or a body). Unless stated otherwise it is null. -

This can be updated during redirects to null as described in -HTTP fetch. +

A byte sequence will be safely extracted +into a body early on in fetch. As part of HTTP fetch it is possible +for this field to be set to null due to certain redirects.


@@ -2328,10 +2329,14 @@ run these steps:

In this section, we define common operations for {{ReadableStream}} objects. [[!STREAMS]] -

To enqueue -chunk into a {{ReadableStream}} object stream, run these steps: +

To enqueue bytes, given a +byte sequence bytes and a {{ReadableStream}} object stream:

    +
  1. Let chunk be a {{Uint8Array}} object wrapping an {{ArrayBuffer}} object + containing bytes. If that threw an exception, error stream + with that exception and return.

  2. +
  3. Call ReadableStreamDefaultControllerEnqueue(stream.\[[readableStreamController]], chunk). @@ -2355,7 +2360,7 @@ run these steps:

To -construct a ReadableStream object +construct a ReadableStream object optionally with a highWaterMark, sizeAlgorithm algorithm, pull action, and cancel action, run these steps: @@ -2392,23 +2397,6 @@ action, and cancel action, run these steps: cancelAlgorithm, highWaterMark, sizeAlgorithm). -

To -construct a fixed ReadableStream object -with given chunks, run these steps: - -

    -
  1. Let stream be the result of - constructing a {{ReadableStream}} - object. - -

  2. For each chunk in chunks, enqueue - chunk into stream. - -

  3. Close stream. - -

  4. Return stream. -
-

To get a reader from a {{ReadableStream}} object stream, run these steps: @@ -2488,13 +2476,6 @@ object stream, run these steps:

  • Return the result of calling ReadableStreamTee(stream, true). -

    An empty {{ReadableStream}} -object is the result of constructing a fixed -{{ReadableStream}} object with an empty list. - -

    Constructing an empty {{ReadableStream}} object will not throw an -exception. -

    A {{ReadableStream}} object stream is said to be readable if stream.\[[state]] is "readable". @@ -3435,6 +3416,16 @@ the request.

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

      +
    1. +

      If request's body is a byte sequence, then: + +

        +
      1. Let body and ignoreType be the result of + safely extracting request's body. + +

      2. Set request's body to body. +

      +
    2. If request's window is "client", set request's window to request's @@ -4925,10 +4916,8 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b ongoing fetch with the aborted flag set.

    3. -

      Let stream be the result of - constructing a {{ReadableStream}} - object with highWaterMark, sizeAlgorithm, pull, and - cancel. +

      Let stream be the result of constructing a ReadableStream object + with highWaterMark, sizeAlgorithm, pull, and cancel.

      This construction operation will not throw an exception. @@ -5007,10 +4996,11 @@ Range Requests. [[HTTP-RANGE]] However, this is not widely supported by b

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

    5. Enqueue a Uint8Array object wrapping an - ArrayBuffer containing bytes to stream. If that threw an - exception, terminate the ongoing fetch, and - error stream with that exception. +

    6. Enqueue bytes given bytes and + stream. + +

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

    8. If stream doesn't need more data and request's synchronous flag is unset, ask the user agent to @@ -5659,7 +5649,7 @@ method steps are: sort and combine with this's header list. -

      Body mixin

      +

      BodyInit unions

       typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) XMLHttpRequestBodyInit;
      @@ -5686,21 +5676,22 @@ typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit;

      To extract a body and a `Content-Type` value from -object, with an optional keepalive flag, run these steps: +object, with an optional boolean keepalive (default false), run +these steps:

        -
      1. Let stream be the result of - constructing a - {{ReadableStream}} object. +

      2. Let stream be object if object is a {{ReadableStream}} + object; otherwise the result of constructing a ReadableStream object.

      3. Let Content-Type be null.

      4. Let action be null. -

      5. Let source be null. +

      6. Let source be null if object is a {{ReadableStream}} object; otherwise + object.

      7. -

        Switch on object's type: +

        Switch on object:

        {{Blob}} @@ -5710,17 +5701,12 @@ typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit;

        If object's {{Blob/type}} attribute is not the empty byte sequence, set Content-Type to its value. -

        Set source to object. +

        byte sequence +

        Set action to an action that returns object.

        BufferSource -
        -

        Enqueue a Uint8Array object - wrapping an ArrayBuffer containing a copy of the bytes held by object - to stream and close - stream. If that threw an exception, - error stream with that exception. - -

        Set source to object. +

        Set action to an action that returns a + copy of the bytes held by object.

        {{FormData}}
        @@ -5734,8 +5720,6 @@ typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit; multipart/form-data boundary string generated by the multipart/form-data encoding algorithm. -

        Set source to object. -

        {{URLSearchParams}}

        Set action to an action that runs the @@ -5747,39 +5731,29 @@ typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit;

        Set Content-Type to `application/x-www-form-urlencoded;charset=UTF-8`. -

        Set source to object. - -

        USVString +
        scalar value string

        Set action to an action that runs UTF-8 encode on object.

        Set Content-Type to `text/plain;charset=UTF-8`. -

        Set source to object. -

        {{ReadableStream}}
        -

        If the keepalive flag is set, then throw a {{TypeError}}. +

        If keepalive is true, then throw a {{TypeError}}.

        If object is disturbed or locked, then throw a {{TypeError}}. - -

        Set stream to object.

      8. If action is non-null, run action in parallel:

          -
        1. Whenever one or more bytes are available, let bytes be the bytes and - enqueue a Uint8Array object - wrapping an ArrayBuffer containing bytes to stream. If - creating the ArrayBuffer threw an exception, - error stream with that exception - and cancel running action. - -

        2. When running action is done, - close stream. +

        3. Whenever one or more bytes are available and stream is not + errored, enqueue bytes given the available + bytes and stream. + +

        4. When running action is done, close stream.

      9. Let body be a body whose stream is @@ -5789,6 +5763,8 @@ typedef (ReadableStream or XMLHttpRequestBodyInit) BodyInit;

      +

      Body mixin

      +
       interface mixin Body {
         readonly attribute ReadableStream? body;
      @@ -5911,17 +5887,24 @@ the associated steps:
        
    9. If object is disturbed or locked, then return a promise rejected with a {{TypeError}}. -

    10. Let stream be object's body's stream - if object's body is non-null; otherwise an empty - {{ReadableStream}} object. +

    11. Let promise be a promise resolved with an empty + byte sequence. -

    12. Let reader be the result of - getting a reader from stream. If that threw - an exception, return a promise rejected with that exception. +

    13. +

      If object's body is non-null, then: -

    14. Let promise be the result of - reading all bytes from stream with - reader. +

        +
      1. Let stream be object's body's + stream. + +

      2. Let reader be the result of + getting a reader from stream. If that + threw an exception, then return a promise rejected with that exception. + +

      3. Set promise to the result of + reading all bytes from stream with + reader. +

    15. Let steps be to return the result of package data with the first argument given, type, and object's MIME type. @@ -6458,7 +6441,7 @@ constructor steps are:

    16. If init["{{RequestInit/keepalive}}"] exists and is true, then set body and Content-Type to the result of extracting - init["{{RequestInit/body}}"], with the keepalive flag set. + init["{{RequestInit/body}}"], with keepalive set to true.

    17. Otherwise, set body and Content-Type to the result of extracting init["{{RequestInit/body}}"].