You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add backpressure information to tee, clone (#16804)
* Add backpressure information to tee, clone
Add information on what causes backpressure to ReadableStream.tee, Request.clone, Response.clone.
* pr feedback: grammar
* Elaborate on tee/clone backpressure
* respond to pr feedback. Use _x_ instead of *x* for emphasis
The **`clone()`** method of the {{domxref("Request")}} interface creates a copy of the current `Request` object.
17
17
18
+
Like the underlying {{domxref("ReadableStream.tee")}} api,
19
+
the {{domxref("Request.body", "body")}} of a cloned `Response`
20
+
will signal backpressure at the rate of the _faster_ consumer of the two bodies,
21
+
and unread data is enqueued internally on the slower consumed `body`
22
+
without any limit or backpressure.
23
+
Beware when you construct a `Request` from a stream and then `clone` it.
24
+
18
25
`clone()` throws a {{jsxref("TypeError")}} if the request body has already been used. In fact, the main reason `clone()` exists is to allow multiple uses of body objects (when they are one-use only.)
19
26
20
27
If you intend to modify the request, you may prefer the {{domxref("Request")}} constructor.
The **`clone()`** method of the {{domxref("Response")}} interface creates a clone of a response object, identical in every way, but stored in a different variable.
17
17
18
+
Like the underlying {{domxref("ReadableStream.tee")}} api,
19
+
the {{domxref("Response.body", "body")}} of a cloned `Response`
20
+
will signal backpressure at the rate of the _faster_ consumer of the two bodies,
21
+
and unread data is enqueued internally on the slower consumed `body`
22
+
without any limit or backpressure.
23
+
Backpressure refers to the mechanism by which the streaming consumer of data
24
+
(in this case, the code that reads the body)
25
+
slows down the producer of data (such as the TCP server)
26
+
so as not to load large amounts of data in memory
27
+
that is waiting to be used by the application.
28
+
If only one cloned branch is consumed, then the entire body will be buffered in memory.
29
+
Therefore, `clone()` is one way to read a response twice in sequence,
30
+
but you should not use it to read very large bodies
31
+
in parallel at different speeds.
32
+
18
33
`clone()` throws a {{jsxref("TypeError")}} if the response body has already been used.
19
34
In fact, the main reason `clone()` exists is to allow multiple uses of body objects (when they are one-use only.)
0 commit comments