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

Function cloneResponse

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

Source from the content-addressed store, hash-verified

338
339// https://fetch.spec.whatwg.org/#concept-response-clone
340function cloneResponse (response) {
341 // To clone a response response, run these steps:
342
343 // 1. If response is a filtered response, then return a new identical
344 // filtered response whose internal response is a clone of response’s
345 // internal response.
346 if (response.internalResponse) {
347 return filterResponse(
348 cloneResponse(response.internalResponse),
349 response.type
350 )
351 }
352
353 // 2. Let newResponse be a copy of response, except for its body.
354 const newResponse = makeResponse({ ...response, body: null })
355
356 // 3. If response’s body is non-null, then set newResponse’s body to the
357 // result of cloning response’s body.
358 if (response.body != null) {
359 newResponse.body = cloneBody(response.body)
360 }
361
362 // 4. Return newResponse.
363 return newResponse
364}
365
366function makeResponse (init) {
367 return {

Callers 3

cloneMethod · 0.70
putMethod · 0.50
#internalMatchAllMethod · 0.50

Calls 3

filterResponseFunction · 0.70
makeResponseFunction · 0.70
cloneBodyFunction · 0.70

Tested by

no test coverage detected