Skip to content

Commit 3183a7a

Browse files
authored
1 parent b8feb1b commit 3183a7a

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// META: global=window,worker
2+
3+
promise_test(async () => {
4+
const stream = new ReadableStream({
5+
start(controller) {
6+
controller.enqueue(new TextEncoder().encode("hello"));
7+
controller.close();
8+
}
9+
});
10+
11+
const r1 = new Request("https://example.com/", { method: "POST", body: stream, duplex: "half" });
12+
const r2 = r1.clone();
13+
assert_false(r2.bodyUsed, "clone should not be marked as used");
14+
assert_not_equals(r2.body, null, "clone should have a body");
15+
16+
// Constructing a new Request from the clone should preserve the body.
17+
const r3 = new Request(r2);
18+
assert_not_equals(r3.body, null, "Request constructed from clone should have a body");
19+
20+
const text = await r3.text();
21+
assert_equals(text, "hello", "body content should be preserved through clone() and new Request()");
22+
}, "new Request(clone) preserves a ReadableStream body that came from clone()");

0 commit comments

Comments
 (0)