Re: [whatwg/fetch] Add `Response.json` static method (PR #1392)

@lucacasonato commented on this pull request.



> @@ -7480,6 +7485,48 @@ are:
  <li><p>Return <var>responseObject</var>.
 </ol>
 
+
+<p>The static
+<dfn method for=Response><code>json(<var>data</var>, <var>init</var>)</code></dfn> method steps

The implementation here has a lot of duplication with `new Response`. I could rewrite this as follows if that is preferred (not real spec text):

1. Create new header list.
2. Fill header list with init.headers.
3. If header list does not contain `content-type`, set it to `application/json`.
4. Let body be `JSON.stringify(body)`.
5. Set init.headers = header list.
5. Return `new Response(body, init)`

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/pull/1392#pullrequestreview-867161133
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/fetch/pull/1392/review/867161133@github.com>

Received on Sunday, 30 January 2022 18:11:00 UTC