mirror of
https://github.com/servo/servo.git
synced 2025-06-25 17:44:33 +01:00
17 lines
448 B
JavaScript
17 lines
448 B
JavaScript
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);
|
|
}
|
|
}
|