diff --git a/Overview.html b/Overview.html index 05eb513b4..e50ce8fe8 100644 --- a/Overview.html +++ b/Overview.html @@ -7,7 +7,7 @@

Fetch

-

Living Standard — Last Updated 5 February 2016

+

Living Standard — Last Updated 13 February 2016

Participate: @@ -222,7 +222,6 @@

3 Infrastructure

  • process request body
  • process request end-of-file
  • process response -
  • process response body
  • process response end-of-file @@ -252,17 +251,18 @@

    3 Infrastructure


    -

    To wait for a response, wait for either end-of-file to have been -pushed to response's body or for -response to have a -termination reason. +

    To wait for a response, if response's +body is non-null, wait for response's +body's stream to be +closed or +errored.

    To read a request, if request's body is non-null, whenever request's body is read from (i.e. is transmitted or read by script), increase request's body's -transmitted with the amount of payload body +transmitted bytes with the amount of payload body bytes transmitted and then queue a fetch task on request to process request body for request. @@ -528,10 +528,37 @@

    3.1.3 Statuses

    3.1.4 Bodies

    -

    A body is a byte stream. It has an associated -transmitted which is an integer and initially 0, -length which is an integer and initially 0, and -error flag which is initially unset. +

    A body consists of: + +

      +
    • +

      A stream (a + ReadableStream object). + +

      This might become a + ReadableByteStream object. While the type might change, the behavior specified + will be equivalent since the hypothetical ReadableByteStream object will have + the same members as the ReadableStream object has today. + +

    • A transmitted bytes (an integer), initially 0. + +

    • A total bytes (an integer), initially 0. +

    + +

    To clone a body +body, run these steps: + +

      +
    1. Let «out1, out2» be the result of + teeing body's + stream. Rethrow any exceptions. + +

    2. Set body's stream to out1. + +

    3. Return a body whose + stream is out2 and other members are copied from + body. +

    To handle content codings given codings and bytes, run these substeps: @@ -964,6 +991,21 @@

    3.1.5 Requests

    See handle fetch for usage of these terms. [SW] +

    To clone a request +request, run these steps: + +

      +
    1. Let newRequest be a copy of request, except for its + body. + +

    2. If request's body is non-null, set + newRequest's body to the result of + cloning request's + body. Rethrow any exceptions. + +

    3. Return newRequest. +

    +

    3.1.6 Responses

    @@ -1127,6 +1169,26 @@

    3.1.6 Responses

    internal response for internal specification algorithms as you will leak information. +

    To clone a response +response, run these steps: + +

      +
    1. If response is a filtered response, + return a new identical filtered response whose internal + response is a clone of response's + internal response. Rethrow any exceptions. + +

    2. Let newResponse be a copy of response, except for its + body. + +

    3. If response's body is non-null, set + newResponse's body to the result of + cloning response's + body. Rethrow any exceptions. + +

    4. Return newResponse. +

    +

    3.2 Authentication entries

    @@ -1254,6 +1316,15 @@

    3.6.1 ReadableStream

    Rethrow any exceptions. +

    To error a +ReadableStream object stream with given +reason, run these steps: + +

      +
    1. Call ErrorReadableStream(stream, + reason). Rethrow any exceptions. +

    +

    To construct a ReadableStream object with given strategy, pull action and cancel action, all of which are optional, run these steps: @@ -1296,23 +1367,7 @@

    3.6.1 ReadableStream

  • Return stream. -

    To construct a -ReadableStream object, given a byte stream -byteStream, run these steps: - -

    This operation is a workaround and will be deleted when we stop using byte streams. - -

      -
    1. Let stream be a ReadableStream object - such that consuming it will result in chunks each of which is a Uint8Array - object wrapping an ArrayBuffer and the result of concatenating them all will be - equivalent to the byte sequence which would be read from byteStream. Rethrow any - exceptions. - -

    2. Return stream. -

    - -

    To get a reader from a +

    To get a reader from a ReadableStream object stream, run these steps:

      @@ -1323,7 +1378,7 @@

      3.6.1 ReadableStream

    1. Return reader.

    -

    To read all bytes from a +

    To read all bytes from a ReadableStream object with reader, run these steps: @@ -1647,8 +1702,7 @@

    5 Fetching

    That is, it either returns a response if request's synchronous flag is set, or it queues tasks annotated - process response, process response body, and - process response end-of-file for the + process response, and process response end-of-file for the response.

    To capture uploads, if request's @@ -1934,7 +1988,7 @@

    5.1 Main fetch

    `HEAD` or `CONNECT`, or internalResponse's status is a null body status, set internalResponse's body to - null and disregard any pushing toward it (if any). + null and disregard any enqueuing toward it (if any).

    This standardizes the error handling for servers that violate HTTP. @@ -1977,41 +2031,9 @@

    5.1 Main fetch

  • Queue a fetch task on request to process response for response. -

  • -

    If internalResponse's - body is null, run these substeps: - -

      -
    1. Queue a fetch task on request to - process response body for response. - -
    2. Queue a fetch-done task using request and - response. -

    - -
  • -

    Otherwise, if internalResponse's - body is non-null, run these substeps: - -

      -
    1. Whenever internalResponse's - body's is pushed to, for and as long as - internalResponse has no - termination reason and - end-of-file has not been pushed, - queue a fetch task on request to - process response body for response. +

    2. Wait for internalResponse. -

    3. -

      Once end-of-file has been pushed to internalResponse's - body or internalResponse has - a termination reason, - queue a fetch-done task using request and - response. - -

      Ideally FTP/HTTP define this in more detail and this becomes a set of - simple hooks. -

    +
  • Queue a fetch-done task using request and response. @@ -2403,8 +2425,8 @@

    5.3 HTTP fetch

    authentication entry for request and the given realm.
  • Return response. Typically - actualResponse's body is still being - pushed to after returning. + actualResponse's body's + stream is still being enqueued to after returning. @@ -2504,9 +2526,8 @@

    5.5 HTTP-network request's window is "no-window" and request's redirect mode is not - "follow", and a copy of request, with - httpRequest's body being a tee - of request's body, otherwise. + "follow", and the result of cloning + request otherwise.

    A request is typically copied as it needs to be possible to add headers and read its @@ -2525,7 +2546,7 @@

    5.5 HTTP-network
  • If httpRequest's body is non-null, set contentLengthValue to httpRequest's body's - length, + total bytes, utf-8 encoded. @@ -2747,8 +2768,8 @@

    5.5 HTTP-network
  • Return response. Typically - response's body is still being - pushed to after returning. + response's body's + stream is still being enqueued to after returning. @@ -2806,6 +2827,30 @@

    5.6 HTTP-network fetchRead request. +
  • +

    Let strategy be an object. The user agent may choose any object. + +

    strategy is used to control the queuing strategy of + stream constructed below. + +

  • Let pull be an action that resumes the + ongoing fetch if it is suspended. + +

  • Let cancel be an action that + terminates the ongoing fetch with reason + end-user abort. + +

  • +

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

    This construction operation will not throw an exception. + +

  • Set response's body to a new + body whose stream is + stream. +

  • Delete `Content-Encoding` from response's @@ -2866,9 +2911,8 @@

    5.6 HTTP-network fetch
  • If response's body is - non-null, set response's - body's - length to response's + non-null, set response's body's + total bytes to response's body's payload body length. @@ -2879,7 +2923,7 @@

    5.6 HTTP-network fetch
  • Increase response's body's - transmitted with bytes' + transmitted bytes with bytes' length.

  • Let codings be the result of @@ -2887,25 +2931,40 @@

    5.6 HTTP-network fetchresponse's header list. -
  • Set bytes to the result of - handling content codings given - codings and bytes. +

  • +

    Set bytes to the result of handling + content codings given codings and bytes. + +

    This makes the `Content-Length` + header unreliable to the extent that it was reliable + to begin with. + +

  • +

    Enqueue a Uint8Array + object wrapping an ArrayBuffer containing bytes to stream. -

  • Push bytes to response's - body. - +

  • If stream doesn't need more + data and request's synchronous flag is unset, ask the user agent + to suspend the ongoing fetch. -

    This means that the `Content-Length` - header is no longer reliable. A - response will still include it, but it cannot be - used, except for debugging and logging purposes. +

  • If at any point the bytes transmission is done normally and stream is + readable, + close stream. + +

  • +

    If at any point fetch is + terminated with reason reason, + run these subsubsteps: + +

      +
    1. Set response's termination + reason to reason. -

    2. If at any point fetch is - terminated with reason - reason, set response's - termination reason to - reason. +
    3. If stream is readable, + error stream with a + TypeError. +

    These are run in parallel @@ -2914,8 +2973,8 @@

    5.6 HTTP-network fetch

    Return response. Typically - response's body is still being - pushed to after returning. + response's body's + stream is still being enqueued to after returning. @@ -3516,14 +3575,17 @@

    6.2 Body mixin

    typedef any JSON;
     typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) BodyInit;
    -

    To extract a byte stream and a +

    To extract a body and a `Content-Type` value from object, run these steps:

      -
    1. Let stream be an empty byte stream. +

    2. Let stream be the result of + constructing a + ReadableStream object.

    3. Let Content-Type be null. +

    4. Let action be null.

    5. Switch on object's type: @@ -3531,25 +3593,25 @@

      6.2 Body mixin

      Blob
      -

      Push a copy of object's contents to stream. +

      Set action to an action that reads object. -

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

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

      BufferSource
      -

      Push a - copy of - object to stream. +

      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.

      FormData
      -

      Push the result of running the +

      Set action to an action that runs the multipart/form-data encoding algorithm, with object as form data set and with - utf-8 as the explicit character encoding, to - stream. + utf-8 as the explicit character encoding. @@ -3561,11 +3623,10 @@

      6.2 Body mixin

      URLSearchParams
      -

      Push the result of running the - application/x-www-form-urlencoded serializer, - with object's - list, to - stream. +

      Set action to an action that runs the + application/x-www-form-urlencoded + serializer with object's + list.

      Set Content-Type to @@ -3573,12 +3634,31 @@

      6.2 Body mixin

      USVString
      -

      Push the result of running utf-8 encode on - object to stream. +

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

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

      -
    6. Return stream and Content-Type. +

    7. +

      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. +

      + +
    8. Let body be a body whose + stream is stream. + +

    9. Return body and Content-Type.

    @@ -3598,18 +3678,25 @@

    6.2 Body mixin

    due course. -

    Objects implementing the Body mixin gain a -MIME type (initially the empty byte sequence). +

    Objects implementing the Body mixin gain an associated +body (null or a body) and +a MIME type (initially the empty byte sequence). -

    Objects implementing the Body mixin must define an associated -disturbed predicate and a -consume body algorithm. +

    An object implementing the Body mixin is said to be +disturbed if body is +non-null and its stream is +disturbed. + +

    An object implementing the Body mixin is said to be +locked if body is +non-null and its stream is +locked.

    The bodyUsed attribute's getter must return true if disturbed, and false otherwise.

    Objects implementing the Body mixin also have an associated -package data algorithm, which given +package data algorithm, given bytes, a type and a MIME type, switches on type, and runs the associated steps: @@ -3675,6 +3762,36 @@

    6.2 Body mixin

    bytes.
  • +

    Objects implementing the Body mixin also have an associated +consume body algorithm, given a type, +runs these steps: + +

      +
    1. If this object is disturbed + or locked, return a new promise rejected with a + TypeError. + +

    2. Let stream be body's + stream if body is + non-null, or an empty + ReadableStream object otherwise. + +

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

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

    5. Return the result of transforming promise by a fulfillment handler that + returns the result of the package data algorithm + with its first argument, type and this object's + MIME type. + +

    +

    The arrayBuffer() method, when invoked, must return the result of running consume body with ArrayBuffer. @@ -3754,51 +3871,16 @@

    6.3 Request class

    will still need to support it as a destination. -

    A Request object has an associated -request (a -request). +

    A Request object has an associated request +(a request).

    A Request object also has an associated Headers object which is itself associated with request's header list. -

    A Request object also has an associated -disturbed flag which is initially unset. - -

    A Request object's disturbed predicate -returns true if the associated request's -body is not null and the associated -disturbed flag is set. - -

    A Request object's consume body -algorithm, given a type, runs these steps: - -

      -
    1. If this Request object is disturbed, - return a new promise rejected with a TypeError. - -

    2. Set disturbed flag. - -

    3. Let p be a new promise. - -

    4. -

      Run these substeps in parallel: -

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

      2. If request's - body is not null, set bytes to the result of - reading from request's - body until it returns end-of-stream. - -

      3. Resolve p with the result of running the - package data algorithm with bytes, - type and MIME type. If that threw an - exception, reject p with that exception. -

      - -
    5. Return p. -

    +

    A Request object's body is its +request's +body.


    @@ -3808,12 +3890,9 @@

    6.3 Request class

    1. If input is a Request object and it is - disturbed, - throw a TypeError. - -

    2. Let temporaryBody be input's - request's body - if input is a Request object, and null otherwise. + disturbed or + locked, throw a + TypeError.

    3. Let request be input's request, if input is a @@ -4043,8 +4122,12 @@

      6.3 Request class

    4. Fill r's Headers object with headers. Rethrow any exceptions. +

    5. Let inputBody be input's + request's body + if input is a Request object, and null otherwise. +

    6. If either init's body member is present and is non-null or - temporaryBody is non-null, and request's + inputBody is non-null, and request's method is `GET` or `HEAD`, throw a TypeError. @@ -4054,11 +4137,11 @@

      6.3 Request class

      substeps:
        -
      1. Let stream and Content-Type be the result of - extracting init's - body member. +

      2. Let Content-Type be null. -

      3. Set temporaryBody to stream. +

      4. Set inputBody and Content-Type to the result of + extracting init's + body member. Rethrow any exceptions.

      5. If Content-Type is non-null and r's request's @@ -4070,7 +4153,7 @@

        6.3 Request class

    7. Set r's request's - body to temporaryBody. + body to inputBody.

    8. Set r's MIME type to @@ -4084,13 +4167,35 @@

      6.3 Request class

      body is non-null, run these substeps:
        +
      1. Let dummyStream be an empty + ReadableStream object. +

      2. Set input's request's - body to an empty byte stream. + body to a new body whose + stream is dummyStream. + +

      3. +

        Let reader be the result of getting a reader + from dummyStream. +

        This operation will not throw an exception. -

      4. Set input's - disturbed flag. +

      5. +

        Read all bytes from + dummyStream with reader. +

        This operation makes dummyStream disturbed.

      +

      These substeps are meant to produce the observable equivalent of + "piping" input's body's + stream into r. That is, input is + left with a body with a + ReadableStream object that is + disturbed and + locked, while the data readable from + r's body's + stream is now equal to what used to be input's, + if input's original body is non-null. +

    9. Return r.

    @@ -4153,23 +4258,16 @@

    6.3 Request class

    run these steps:
      -
    1. If this Request object is disturbed, +

    2. If this Request object is disturbed + or locked, throw a TypeError. -

    3. Let newRequest be a copy of - request, with - newRequest's body being a tee of - request's - body. - - -

    4. Let r be a new Request object associated with - newRequest and a new Headers object whose +

    5. Return a new Request object associated with the result of + cloning + request and a new Headers object whose guard is context object's Headers' guard. - -

    6. Return r.

    @@ -4211,52 +4309,8 @@

    6.4 Response class

    is itself associated with response's header list. -

    A Response object also has an associated -readable stream which is null or a -ReadableStream object. Its initial value is null. - -

    This might become a -ReadableByteStream object. While the type might change, the behavior specified will -be equivalent since the hypothetical ReadableByteStream object will have the same -members as the ReadableStream object has today. - -

    A Response object is said to be locked if -the associated readable stream is not null and -it is locked. - -

    A Response object's disturbed predicate -returns true if the associated readable stream -is not null and it is disturbed. - -

    A Response object's consume body -algorithm, given a type, runs these steps: - -

      -
    1. If this Response object is disturbed - or locked, return a new promise rejected with a - TypeError. - -

    2. Let stream be readable - stream. - -

    3. If stream is null, set stream to an - empty - ReadableStream object. - -

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

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

    6. Return the result of transforming promise by a fulfillment handler that - returns the result of the package data algorithm - with its first argument, type and MIME type. - -

    +

    A Response object's body is its +response's body.

    The Response(body, init) @@ -4309,14 +4363,11 @@

    6.4 Response class

    101 is included in null body status due to its use elsewhere. It does not affect this step. -

  • Let byteStream and Content-Type be the result of - extracting body. +

  • Let Content-Type be null. -

  • Set r's - readable stream to the result of - constructing a - ReadableStream object with byteStream. - Rethrow any exceptions. +

  • Set r's response's + body and Content-Type to the result of + extracting body. Rethrow any exceptions.

  • If Content-Type is non-null and r's response's @@ -4416,8 +4467,9 @@

    6.4 Response class

    The headers attribute's getter must return the associated Headers object. -

    The body attribute's getter must return the -associated readable stream. +

    The body attribute's getter must return null if +the associated body is null and the associated +body's stream otherwise.


    @@ -4426,32 +4478,15 @@

    6.4 Response class

    1. If this Response object is disturbed - or locked, throw a - TypeError. - -

    2. Let newResponse be a copy of - response except its - body. + or locked, + throw a TypeError. -

    3. Let r be a new Response object associated with - newResponse and a new Headers object whose +

    4. Return a new Response object associated with the result of + cloning + response and a new Headers object whose guard is context object's Headers' guard. - -

    5. If readable stream is null, Return - r. - -

    6. Let «out1, out2» be the result of - teeing - readable stream. Rethrow any exceptions. - -

    7. Set readable stream to out1. - -

    8. Set r's readable stream to - out2. - -

    9. Return r.

    @@ -4505,72 +4540,11 @@

    6.6 Fetch method

    "error", reject p with a TypeError and terminate these substeps. -
  • Let responseObject be a new Response object associated with +

  • Resolve p with a new Response object associated with response and a new Headers object whose guard is "immutable". - -

  • If response's body is null, resolve - p with responseObject and terminate these substeps. - -

  • Let pull be an action that resumes the - ongoing fetch if it is suspended. - -

  • Let cancel be an action that - terminates the ongoing fetch with reason - end-user abort. - -

  • -

    Let strategy be an object. The user agent may choose any object. -

    strategy is used to control the queuing strategy of - stream constructed below. - -

  • -

    Set stream to the result of - constructing a - ReadableStream object with strategy, - pull and cancel. If that threw an exception, run the following - subsubsteps and terminate these substeps: - -

      -
    1. Reject p with that exception. - -

    2. Terminate the ongoing fetch with reason - fatal. -

    - -
  • Set responseObject's readable - stream to stream. - -

  • Resolve p with responseObject. -

    To process response body for response, run these substeps: - -

      -
    1. If stream is null, terminate these substeps. - -

    2. -

      Enqueue a Uint8Array - object wrapping an ArrayBuffer containing the result of reading - response's body into stream. If - that threw an exception, run the following subsubsteps and terminate these substeps: - -

        -
      1. Reject p with that exception. - -

      2. Terminate the ongoing fetch with reason - fatal. -

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

    - -

    To process response end-of-file for response, - close stream - if stream is not null. -

  • Return p. diff --git a/Overview.src.html b/Overview.src.html index 566ddca06..c2f5cfcc5 100644 --- a/Overview.src.html +++ b/Overview.src.html @@ -160,7 +160,6 @@

    Infrastructure

  • process request body
  • process request end-of-file
  • process response -
  • process response body
  • process response end-of-file @@ -190,17 +189,18 @@

    Infrastructure


    -

    To wait for a response, wait for either end-of-file to have been -pushed to response's body or for -response to have a -termination reason. +

    To wait for a response, if response's +body is non-null, wait for response's +body's stream to be +closed or +errored.

    To read a request, if request's body is non-null, whenever request's body is read from (i.e. is transmitted or read by script), increase request's body's -transmitted with the amount of payload body +transmitted bytes with the amount of payload body bytes transmitted and then queue a fetch task on request to process request body for request. @@ -466,10 +466,37 @@

    Statuses

    Bodies

    -

    A body is a byte stream. It has an associated -transmitted which is an integer and initially 0, -length which is an integer and initially 0, and -error flag which is initially unset. +

    A body consists of: + +

    + +

    To clone a body +body, run these steps: + +

      +
    1. Let «out1, out2» be the result of + teeing body's + stream. Rethrow any exceptions. + +

    2. Set body's stream to out1. + +

    3. Return a body whose + stream is out2 and other members are copied from + body. +

    To handle content codings given codings and bytes, run these substeps: @@ -902,6 +929,21 @@

    Requests

    See handle fetch for usage of these terms. SW +

    To clone a request +request, run these steps: + +

      +
    1. Let newRequest be a copy of request, except for its + body. + +

    2. If request's body is non-null, set + newRequest's body to the result of + cloning request's + body. Rethrow any exceptions. + +

    3. Return newRequest. +

    +

    Responses

    @@ -1065,6 +1107,26 @@

    Responses

    internal response for internal specification algorithms as you will leak information. +

    To clone a response +response, run these steps: + +

      +
    1. If response is a filtered response, + return a new identical filtered response whose internal + response is a clone of response's + internal response. Rethrow any exceptions. + +

    2. Let newResponse be a copy of response, except for its + body. + +

    3. If response's body is non-null, set + newResponse's body to the result of + cloning response's + body. Rethrow any exceptions. + +

    4. Return newResponse. +

    +

    Authentication entries

    @@ -1192,6 +1254,15 @@

    ReadableStream

    Rethrow any exceptions. +

    To error a +ReadableStream object stream with given +reason, run these steps: + +

      +
    1. Call ErrorReadableStream(stream, + reason). Rethrow any exceptions. +

    +

    To construct a ReadableStream object with given strategy, pull action and cancel action, all of which are optional, run these steps: @@ -1234,23 +1305,7 @@

    ReadableStream

  • Return stream. -

    To construct a -ReadableStream object, given a byte stream -byteStream, run these steps: - -

    This operation is a workaround and will be deleted when we stop using byte streams. - -

      -
    1. Let stream be a ReadableStream object - such that consuming it will result in chunks each of which is a Uint8Array - object wrapping an ArrayBuffer and the result of concatenating them all will be - equivalent to the byte sequence which would be read from byteStream. Rethrow any - exceptions. - -

    2. Return stream. -

    - -

    To get a reader from a +

    To get a reader from a ReadableStream object stream, run these steps:

      @@ -1261,7 +1316,7 @@

      ReadableStream

    1. Return reader.

    -

    To read all bytes from a +

    To read all bytes from a ReadableStream object with reader, run these steps: @@ -1585,8 +1640,7 @@

    Fetching

    That is, it either returns a response if request's synchronous flag is set, or it queues tasks annotated - process response, process response body, and - process response end-of-file for the + process response, and process response end-of-file for the response.

    To capture uploads, if request's @@ -1872,7 +1926,7 @@

    Main fetch

    `HEAD` or `CONNECT`, or internalResponse's status is a null body status, set internalResponse's body to - null and disregard any pushing toward it (if any). + null and disregard any enqueuing toward it (if any).

    This standardizes the error handling for servers that violate HTTP. @@ -1915,41 +1969,9 @@

    Main fetch

  • Queue a fetch task on request to process response for response. -

  • -

    If internalResponse's - body is null, run these substeps: - -

      -
    1. Queue a fetch task on request to - process response body for response. - -
    2. Queue a fetch-done task using request and - response. -

    - -
  • -

    Otherwise, if internalResponse's - body is non-null, run these substeps: - -

      -
    1. Whenever internalResponse's - body's is pushed to, for and as long as - internalResponse has no - termination reason and - end-of-file has not been pushed, - queue a fetch task on request to - process response body for response. +

    2. Wait for internalResponse. -

    3. -

      Once end-of-file has been pushed to internalResponse's - body or internalResponse has - a termination reason, - queue a fetch-done task using request and - response. - -

      Ideally FTP/HTTP define this in more detail and this becomes a set of - simple hooks. -

    +
  • Queue a fetch-done task using request and response. @@ -2341,8 +2363,8 @@

    HTTP fetch

    authentication entry for request and the given realm.
  • Return response. Typically - actualResponse's body is still being - pushed to after returning. + actualResponse's body's + stream is still being enqueued to after returning. @@ -2442,9 +2464,8 @@

    HTTP-network-or-cache fetch

    request's window is "no-window" and request's redirect mode is not - "follow", and a copy of request, with - httpRequest's body being a tee - of request's body, otherwise. + "follow", and the result of cloning + request otherwise.

    A request is typically copied as it needs to be possible to add headers and read its @@ -2463,7 +2484,7 @@

    HTTP-network-or-cache fetch

  • If httpRequest's body is non-null, set contentLengthValue to httpRequest's body's - length, + total bytes, utf-8 encoded. @@ -2685,8 +2706,8 @@

    HTTP-network-or-cache fetch

  • Return response. Typically - response's body is still being - pushed to after returning. + response's body's + stream is still being enqueued to after returning. @@ -2744,6 +2765,30 @@

    HTTP-network fetch

    Read request. +

  • +

    Let strategy be an object. The user agent may choose any object. + +

    strategy is used to control the queuing strategy of + stream constructed below. + +

  • Let pull be an action that resumes the + ongoing fetch if it is suspended. + +

  • Let cancel be an action that + terminates the ongoing fetch with reason + end-user abort. + +

  • +

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

    This construction operation will not throw an exception. + +

  • Set response's body to a new + body whose stream is + stream. +

  • Delete `Content-Encoding` from response's @@ -2804,9 +2849,8 @@

    HTTP-network fetch

    1. If response's body is - non-null, set response's - body's - length to response's + non-null, set response's body's + total bytes to response's body's payload body length. @@ -2817,7 +2861,7 @@

      HTTP-network fetch

      1. Increase response's body's - transmitted with bytes' + transmitted bytes with bytes' length.

      2. Let codings be the result of @@ -2825,25 +2869,40 @@

        HTTP-network fetch

        in response's header list. -
      3. Set bytes to the result of - handling content codings given - codings and bytes. +

      4. +

        Set bytes to the result of handling + content codings given codings and bytes. + +

        This makes the `Content-Length` + header unreliable to the extent that it was reliable + to begin with. + +

      5. +

        Enqueue a Uint8Array + object wrapping an ArrayBuffer containing bytes to stream. -

      6. Push bytes to response's - body. - +

      7. If stream doesn't need more + data and request's synchronous flag is unset, ask the user agent + to suspend the ongoing fetch.

      -

      This means that the `Content-Length` - header is no longer reliable. A - response will still include it, but it cannot be - used, except for debugging and logging purposes. +

    2. If at any point the bytes transmission is done normally and stream is + readable, + close stream. + +

    3. +

      If at any point fetch is + terminated with reason reason, + run these subsubsteps: + +

        +
      1. Set response's termination + reason to reason. -

      2. If at any point fetch is - terminated with reason - reason, set response's - termination reason to - reason. +
      3. If stream is readable, + error stream with a + TypeError. +

    These are run in parallel @@ -2852,8 +2911,8 @@

    HTTP-network fetch

    might be a redirect).
  • Return response. Typically - response's body is still being - pushed to after returning. + response's body's + stream is still being enqueued to after returning. @@ -3454,14 +3513,17 @@

    Body mixin

    typedef any JSON;
     typedef (Blob or BufferSource or FormData or URLSearchParams or USVString) BodyInit;
    -

    To extract a byte stream and a +

    To extract a body and a `Content-Type` value from object, run these steps:

      -
    1. Let stream be an empty byte stream. +

    2. Let stream be the result of + constructing a + ReadableStream object.

    3. Let Content-Type be null. +

    4. Let action be null.

    5. Switch on object's type: @@ -3469,25 +3531,25 @@

      Body mixin

      Blob
      -

      Push a copy of object's contents to stream. +

      Set action to an action that reads object. -

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

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

      BufferSource
      -

      Push a - copy of - object to stream. +

      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.

      FormData
      -

      Push the result of running the +

      Set action to an action that runs the multipart/form-data encoding algorithm, with object as form data set and with - utf-8 as the explicit character encoding, to - stream. + utf-8 as the explicit character encoding. @@ -3499,11 +3561,10 @@

      Body mixin

      URLSearchParams
      -

      Push the result of running the - application/x-www-form-urlencoded serializer, - with object's - list, to - stream. +

      Set action to an action that runs the + application/x-www-form-urlencoded + serializer with object's + list.

      Set Content-Type to @@ -3511,12 +3572,31 @@

      Body mixin

      USVString
      -

      Push the result of running utf-8 encode on - object to stream. +

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

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

      -
    6. Return stream and Content-Type. +

    7. +

      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. +

      + +
    8. Let body be a body whose + stream is stream. + +

    9. Return body and Content-Type.

    @@ -3536,18 +3616,25 @@

    Body mixin

    due course. -

    Objects implementing the Body mixin gain a -MIME type (initially the empty byte sequence). +

    Objects implementing the Body mixin gain an associated +body (null or a body) and +a MIME type (initially the empty byte sequence). -

    Objects implementing the Body mixin must define an associated -disturbed predicate and a -consume body algorithm. +

    An object implementing the Body mixin is said to be +disturbed if body is +non-null and its stream is +disturbed. + +

    An object implementing the Body mixin is said to be +locked if body is +non-null and its stream is +locked.

    The bodyUsed attribute's getter must -return true if disturbed, and false otherwise. +return true if disturbed, and false otherwise.

    Objects implementing the Body mixin also have an associated -package data algorithm, which given +package data algorithm, given bytes, a type and a MIME type, switches on type, and runs the associated steps: @@ -3613,6 +3700,36 @@

    Body mixin

    bytes. +

    Objects implementing the Body mixin also have an associated +consume body algorithm, given a type, +runs these steps: + +

      +
    1. If this object is disturbed + or locked, return a new promise rejected with a + TypeError. + +

    2. Let stream be body's + stream if body is + non-null, or an empty + ReadableStream object otherwise. + +

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

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

    5. Return the result of transforming promise by a fulfillment handler that + returns the result of the package data algorithm + with its first argument, type and this object's + MIME type. + +

    +

    The arrayBuffer() method, when invoked, must return the result of running consume body with ArrayBuffer. @@ -3692,51 +3809,16 @@

    Request class

    will still need to support it as a destination. -

    A Request object has an associated -request (a -request). +

    A Request object has an associated request +(a request).

    A Request object also has an associated Headers object which is itself associated with request's header list. -

    A Request object also has an associated -disturbed flag which is initially unset. - -

    A Request object's disturbed predicate -returns true if the associated request's -body is not null and the associated -disturbed flag is set. - -

    A Request object's consume body -algorithm, given a type, runs these steps: - -

      -
    1. If this Request object is disturbed, - return a new promise rejected with a TypeError. - -

    2. Set disturbed flag. - -

    3. Let p be a new promise. - -

    4. -

      Run these substeps in parallel: -

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

      2. If request's - body is not null, set bytes to the result of - reading from request's - body until it returns end-of-stream. - -

      3. Resolve p with the result of running the - package data algorithm with bytes, - type and MIME type. If that threw an - exception, reject p with that exception. -

      - -
    5. Return p. -

    +

    A Request object's body is its +request's +body.


    @@ -3746,12 +3828,9 @@

    Request class

    1. If input is a Request object and it is - disturbed, - throw a TypeError. - -

    2. Let temporaryBody be input's - request's body - if input is a Request object, and null otherwise. + disturbed or + locked, throw a + TypeError.

    3. Let request be input's request, if input is a @@ -3981,8 +4060,12 @@

      Request class

    4. Fill r's Headers object with headers. Rethrow any exceptions. +

    5. Let inputBody be input's + request's body + if input is a Request object, and null otherwise. +

    6. If either init's body member is present and is non-null or - temporaryBody is non-null, and request's + inputBody is non-null, and request's method is `GET` or `HEAD`, throw a TypeError. @@ -3992,11 +4075,11 @@

      Request class

      substeps:
        -
      1. Let stream and Content-Type be the result of - extracting init's - body member. +

      2. Let Content-Type be null. -

      3. Set temporaryBody to stream. +

      4. Set inputBody and Content-Type to the result of + extracting init's + body member. Rethrow any exceptions.

      5. If Content-Type is non-null and r's request's @@ -4008,7 +4091,7 @@

        Request class

    7. Set r's request's - body to temporaryBody. + body to inputBody.

    8. Set r's MIME type to @@ -4022,13 +4105,35 @@

      Request class

      body is non-null, run these substeps:
        +
      1. Let dummyStream be an empty + ReadableStream object. +

      2. Set input's request's - body to an empty byte stream. + body to a new body whose + stream is dummyStream. + +

      3. +

        Let reader be the result of getting a reader + from dummyStream. +

        This operation will not throw an exception. -

      4. Set input's - disturbed flag. +

      5. +

        Read all bytes from + dummyStream with reader. +

        This operation makes dummyStream disturbed.

      +

      These substeps are meant to produce the observable equivalent of + "piping" input's body's + stream into r. That is, input is + left with a body with a + ReadableStream object that is + disturbed and + locked, while the data readable from + r's body's + stream is now equal to what used to be input's, + if input's original body is non-null. +

    9. Return r.

    @@ -4091,23 +4196,16 @@

    Request class

    run these steps:
      -
    1. If this Request object is disturbed, +

    2. If this Request object is disturbed + or locked, throw a TypeError. -

    3. Let newRequest be a copy of - request, with - newRequest's body being a tee of - request's - body. - - -

    4. Let r be a new Request object associated with - newRequest and a new Headers object whose +

    5. Return a new Request object associated with the result of + cloning + request and a new Headers object whose guard is context object's Headers' guard. - -

    6. Return r.

    @@ -4149,52 +4247,8 @@

    Response class

    is itself associated with response's header list. -

    A Response object also has an associated -readable stream which is null or a -ReadableStream object. Its initial value is null. - -

    This might become a -ReadableByteStream object. While the type might change, the behavior specified will -be equivalent since the hypothetical ReadableByteStream object will have the same -members as the ReadableStream object has today. - -

    A Response object is said to be locked if -the associated readable stream is not null and -it is locked. - -

    A Response object's disturbed predicate -returns true if the associated readable stream -is not null and it is disturbed. - -

    A Response object's consume body -algorithm, given a type, runs these steps: - -

      -
    1. If this Response object is disturbed - or locked, return a new promise rejected with a - TypeError. - -

    2. Let stream be readable - stream. - -

    3. If stream is null, set stream to an - empty - ReadableStream object. - -

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

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

    6. Return the result of transforming promise by a fulfillment handler that - returns the result of the package data algorithm - with its first argument, type and MIME type. - -

    +

    A Response object's body is its +response's body.

    The Response(body, init) @@ -4247,14 +4301,11 @@

    Response class

    101 is included in null body status due to its use elsewhere. It does not affect this step. -

  • Let byteStream and Content-Type be the result of - extracting body. +

  • Let Content-Type be null. -

  • Set r's - readable stream to the result of - constructing a - ReadableStream object with byteStream. - Rethrow any exceptions. +

  • Set r's response's + body and Content-Type to the result of + extracting body. Rethrow any exceptions.

  • If Content-Type is non-null and r's response's @@ -4354,8 +4405,9 @@

    Response class

    The headers attribute's getter must return the associated Headers object. -

    The body attribute's getter must return the -associated readable stream. +

    The body attribute's getter must return null if +the associated body is null and the associated +body's stream otherwise.


    @@ -4364,32 +4416,15 @@

    Response class

    1. If this Response object is disturbed - or locked, throw a - TypeError. - -

    2. Let newResponse be a copy of - response except its - body. + or locked, + throw a TypeError. -

    3. Let r be a new Response object associated with - newResponse and a new Headers object whose +

    4. Return a new Response object associated with the result of + cloning + response and a new Headers object whose guard is context object's Headers' guard. - -

    5. If readable stream is null, Return - r. - -

    6. Let «out1, out2» be the result of - teeing - readable stream. Rethrow any exceptions. - -

    7. Set readable stream to out1. - -

    8. Set r's readable stream to - out2. - -

    9. Return r.

    @@ -4443,72 +4478,11 @@

    Fetch method

    "error", reject p with a TypeError and terminate these substeps. -
  • Let responseObject be a new Response object associated with +

  • Resolve p with a new Response object associated with response and a new Headers object whose guard is "immutable". - -

  • If response's body is null, resolve - p with responseObject and terminate these substeps. - -

  • Let pull be an action that resumes the - ongoing fetch if it is suspended. - -

  • Let cancel be an action that - terminates the ongoing fetch with reason - end-user abort. - -

  • -

    Let strategy be an object. The user agent may choose any object. -

    strategy is used to control the queuing strategy of - stream constructed below. - -

  • -

    Set stream to the result of - constructing a - ReadableStream object with strategy, - pull and cancel. If that threw an exception, run the following - subsubsteps and terminate these substeps: - -

      -
    1. Reject p with that exception. - -

    2. Terminate the ongoing fetch with reason - fatal. -

    - -
  • Set responseObject's readable - stream to stream. - -

  • Resolve p with responseObject. -

    To process response body for response, run these substeps: - -

      -
    1. If stream is null, terminate these substeps. - -

    2. -

      Enqueue a Uint8Array - object wrapping an ArrayBuffer containing the result of reading - response's body into stream. If - that threw an exception, run the following subsubsteps and terminate these substeps: - -

        -
      1. Reject p with that exception. - -

      2. Terminate the ongoing fetch with reason - fatal. -

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

    - -

    To process response end-of-file for response, - close stream - if stream is not null. -

  • Return p.