Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /fetch/api/request/request-clone-readable-stream-body.any.html - WPT Dashboard Interop Dashboard
- /fetch/api/request/request-clone-readable-stream-body.any.serviceworker.html - WPT Dashboard Interop Dashboard
- /fetch/api/request/request-clone-readable-stream-body.any.sharedworker.html - WPT Dashboard Interop Dashboard
- /fetch/api/request/request-clone-readable-stream-body.any.worker.html - WPT Dashboard Interop Dashboard
// META: global=window,worker
promise_test(async () => {
const stream = new ReadableStream({
start(controller) {
controller.enqueue(new TextEncoder().encode("hello"));
controller.close();
}
});
const r2 = r1.clone();
assert_false(r2.bodyUsed, "clone should not be marked as used");
assert_not_equals(r2.body, null, "clone should have a body");
// Constructing a new Request from the clone should preserve the body.
const r3 = new Request(r2);
assert_not_equals(r3.body, null, "Request constructed from clone should have a body");
const text = await r3.text();
assert_equals(text, "hello", "body content should be preserved through clone() and new Request()");
}, "new Request(clone) preserves a ReadableStream body that came from clone()");