summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/api/response/response-stream-disturbed-util.js
blob: 50bb586aa0743966e4d626a52e3051ba47b7768c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const BODY = '{"key": "value"}';

function responseFromBodySource(bodySource) {
  if (bodySource === "fetch") {
    return fetch("../resources/data.json");
  } else if (bodySource === "stream") {
    const stream = new ReadableStream({
      start(controller) {
        controller.enqueue(new TextEncoder().encode(BODY));
        controller.close();
      },
    });
    return new Response(stream);
  } else {
    return new Response(BODY);
  }
}