MCPcopy
hub / github.com/nock/nock / continueWithResponseBody

Function continueWithResponseBody

lib/playback_interceptor.js:254–291  ·  view source on GitHub ↗
(
    rawBody,
    fullResponseStatus,
    fullResponseRawHeaders = [],
  )

Source from the content-addressed store, hash-verified

252 }
253
254 async function continueWithResponseBody(
255 rawBody,
256 fullResponseStatus,
257 fullResponseRawHeaders = [],
258 ) {
259 const headers = await prepareResponseHeaders(
260 rawBody,
261 fullResponseRawHeaders,
262 )
263 const bodyAsStream = convertBodyToStream(rawBody)
264 bodyAsStream.resume()
265
266 // TODO: there is probably a better way to support delay.
267 // Wrap the stream in a duplex stream to support the delay.
268 const readable = new stream.Readable({
269 read() {},
270 })
271 bodyAsStream.on('data', function (chunk) {
272 readable.push(chunk)
273 })
274 bodyAsStream.on('end', function () {
275 common.setTimeout(() => {
276 readable.push(null)
277 interceptor.scope.emit('replied', decompressedRequest, interceptor)
278 }, interceptor.delayBodyInMs)
279 })
280 bodyAsStream.on('error', function (err) {
281 readable.emit('error', err)
282 })
283
284 const status = interceptor.statusCode || fullResponseStatus
285 const hasBody = FetchResponse.isResponseWithBody(status)
286 return new Response(hasBody ? readable : null, {
287 status,
288 statusText: STATUS_CODES[status],
289 headers,
290 })
291 }
292}
293
294module.exports = { playbackInterceptor }

Callers 2

playbackInterceptorFunction · 0.85
continueWithFullResponseFunction · 0.85

Calls 4

prepareResponseHeadersFunction · 0.85
convertBodyToStreamFunction · 0.85
onMethod · 0.80
emitMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…