MCPcopy Create free account
hub / github.com/nodejs/node / clone

Method clone

deps/undici/src/lib/web/fetch/response.js:230–253  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

228
229 // Returns a clone of response.
230 clone () {
231 webidl.brandCheck(this, Response)
232
233 // 1. If this is unusable, then throw a TypeError.
234 if (bodyUnusable(this.#state)) {
235 throw webidl.errors.exception({
236 header: 'Response.clone',
237 message: 'Body has already been consumed.'
238 })
239 }
240
241 // 2. Let clonedResponse be the result of cloning this’s response.
242 const clonedResponse = cloneResponse(this.#state)
243
244 // Note: To re-register because of a new stream.
245 // Don't set finalizers other than for fetch responses.
246 if (this.#state.urlList.length !== 0 && this.#state.body?.stream) {
247 streamRegistry.register(this, new WeakRef(this.#state.body.stream))
248 }
249
250 // 3. Return the result of creating a Response object, given
251 // clonedResponse, this’s headers’s guard, and this’s relevant Realm.
252 return fromInnerResponse(clonedResponse, getHeadersGuard(this.#headers))
253 }
254
255 [nodeUtil.inspect.custom] (depth, options) {
256 if (options.depth === null) {

Callers

nothing calls this directly

Calls 6

brandCheckMethod · 0.80
exceptionMethod · 0.80
bodyUnusableFunction · 0.70
cloneResponseFunction · 0.70
fromInnerResponseFunction · 0.70
registerMethod · 0.45

Tested by

no test coverage detected