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
feat(node): add clone() support to ImpitResponse (#419)
## Summary
Implements `Response.clone()` on `ImpitResponse` using
`ReadableStream.tee()`, making impit compatible with libraries like
[ky](https://github.com/sindresorhus/ky) that call `response.clone()`
internally.
## Approach
When `.clone()` is called:
1. `this.body.tee()` splits the underlying `ReadableStream` into two
independent streams (synchronous, no eager buffering)
2. The original response's `.body` getter and body methods (`text`,
`json`, `arrayBuffer`, `bytes`) are re-patched to read from one stream
3. A standard `Response` is returned as the clone, backed by the other
stream
Multiple clones are supported (matching the Fetch spec) — each call tees
the current branch, so the original and all clones can be read
independently.
Charset-aware `text()` decoding is preserved on the original via
`decodeBuffer`. The clone uses standard `Response.text()` (UTF-8).
Throws `TypeError` on clone after body consumption, matching Fetch API
semantics.
## Changes
- **`index.wrapper.js`** — add `clone()` in `#wrapResponse`, re-patch
`.body` getter and body methods with `configurable: true` so subsequent
clones work
- **`dts-header.d.ts`** — add `clone(): Response` to `ImpitResponse` via
declaration merging
- **`test/basics.test.ts`** — tests covering: return type, url/header
preservation, independent body reads, text() on both, multiple clones,
body streaming after clone, clone-after-consume error, arrayBuffer on
both, read ordering, non-200 status
---------
Co-authored-by: Jindřich Bär <jindrichbar@gmail.com>
0 commit comments