diff --git a/fetch.bs b/fetch.bs index 6471179cb..02b64f038 100644 --- a/fetch.bs +++ b/fetch.bs @@ -7443,6 +7443,7 @@ interface Response { [NewObject] static Response error(); [NewObject] static Response redirect(USVString url, optional unsigned short status = 302); + [NewObject] static Response json(any data, optional ResponseInit init = {}); readonly attribute ResponseType type; @@ -7494,6 +7495,10 @@ enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredire

Creates a redirect {{Response}} that redirects to url with status status. +

response = Response . json(data [, init]) +

Creates a {{Response}} whose body is the JSON-encoded data, and status, status + message, and headers are provided by init. +

response . type

Returns response's type, e.g., "cors". @@ -7539,11 +7544,9 @@ enum ResponseType { "basic", "cors", "default", "error", "opaque", "opaqueredire

  • Return responseObject. -


    - -

    The -new Response(body, init) -constructor steps are: +

    To initialize a response, given a {{Response}} object response, +{{ResponseInit}} init, and an optional body with type body, run +these steps:

    1. If init["{{ResponseInit/status}}"] is not in the range 200 to 599, inclusive, @@ -7552,50 +7555,61 @@ constructor steps are:

    2. If init["{{ResponseInit/statusText}}"] does not match the reason-phrase token production, then throw a {{TypeError}}. -

    3. Set this's response to a new response. - -

    4. Set this's headers to a new {{Headers}} object with - this's relevant Realm, whose header list is this's - response's header list and guard is - "response". - -

    5. Set this's response's status to +

    6. Set response's response's status to init["{{ResponseInit/status}}"]. -

    7. Set this's response's status message to - init["{{ResponseInit/statusText}}"]. +

    8. Set response's response's status message + to init["{{ResponseInit/statusText}}"].

    9. If init["{{ResponseInit/headers}}"] exists, then - fill this's headers with + fill response's headers with init["{{ResponseInit/headers}}"].

    10. -

      If body is non-null, then: +

      If body was given, then:

      1. -

        If init["{{ResponseInit/status}}"] is a null body status, then throw - a {{TypeError}}. +

        If response's status is a null body status, then + throw a {{TypeError}}.

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

      2. Let bodyWithType be the result of extracting - body. - -

      3. Set this's response's body to - bodyWithType's body. +

      4. Set response's body to body's + body. -

      5. Let type be bodyWithType's type. - -

      6. If type is non-null and this's response's - header list does not contain +

      7. If body's type is non-null and + response's header list does not contain `Content-Type`, then append (`Content-Type`, - type) to this's response's + body's type) to response's header list.

    +
    + +

    The +new Response(body, init) +constructor steps are: + +

      +
    1. Set this's response to a new response. + +

    2. Set this's headers to a new {{Headers}} object with + this's relevant Realm, whose header list is this's + response's header list and guard is + "response". + +

    3. Let bodyWithType be null. + +

    4. If body is non-null, then set bodyWithType to the result of + extracting body. + +

    5. Perform initialize a response given this, init, and + bodyWithType. +

    +

    The static error() method steps are to return the result of creating a {{Response}} object, given a new network error, "immutable", and this's relevant Realm. @@ -7628,6 +7642,27 @@ are:

  • Return responseObject. + +

    The static +json(data, init) method steps +are: + +

      +
    1. Let bytes the result of running serialize a JavaScript value to JSON bytes + on data. + +

    2. Let body be the result of extracting bytes. + +

    3. Let responseObject be the result of creating a {{Response}} + object, given a new response, "response", and this's + relevant Realm. + +

    4. Perform initialize a response given responseObject, init, and + (body, "application/json"). + +

    5. Return responseObject. +

    +

    The type getter steps are to return this's response's type.