Skip to content

Commit

Permalink
fix: Add documentation for Request.prototype.clone()
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeChampion committed Aug 31, 2023
1 parent 0e330b5 commit 9d12321
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions documentation/docs/globals/Request/prototype/clone.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
# Request.clone()

The **`clone()`** method of the `Request` interface creates a copy of the current `Request` object.

Like the underlying `ReadableStream.tee`` api, the `body` of a cloned `Response`
will signal backpressure at the rate of the _faster_ consumer of the two bodies,
and unread data is enqueued internally on the slower consumed `body`
without any limit or backpressure.
Beware when you construct a `Request` from a stream and then `clone` it.

`clone()` throws a `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.)

If you intend to modify the request, you may prefer the `Request` constructor.

## Syntax

```js
clone()
```

### Parameters

None.

### Return value

A `Request` object, which is an exact copy of the `Request` that `clone()` was called on.

0 comments on commit 9d12321

Please sign in to comment.