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:
If init["{{ResponseInit/status}}"] is not in the range 200 to 599, inclusive, @@ -7552,50 +7555,61 @@ constructor steps are:
If init["{{ResponseInit/statusText}}"] does not match the reason-phrase token production, then throw a {{TypeError}}. -
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
".
-
-
Set response's response's status to init["{{ResponseInit/status}}"]. -
Set this's response's status message to - init["{{ResponseInit/statusText}}"]. +
Set response's response's status message + to init["{{ResponseInit/statusText}}"].
If init["{{ResponseInit/headers}}"] exists, then - fill this's headers with + fill response's headers with init["{{ResponseInit/headers}}"].
If body is non-null, then: +
If body was given, then:
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. -
Let bodyWithType be the result of extracting - body. - -
Let type be bodyWithType's type. - -
If type is non-null and this's response's - header list does not contain +
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:
+
+
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
".
+
+
Let bodyWithType be null. + +
If body is non-null, then set bodyWithType to the result of + extracting body. + +
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:
+
+
Let bytes the result of running serialize a JavaScript value to JSON bytes + on data. + +
Let body be the result of extracting bytes. + +
Let responseObject be the result of creating a {{Response}}
+ object, given a new response, "response
", and this's
+ relevant Realm.
+
+
Perform initialize a response given responseObject, init, and
+ (body, "application/json
").
+
+
Return responseObject. +