nock 14.0.14 → 14.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/playback_interceptor.js +7 -22
- package/package.json +1 -1
|
@@ -273,27 +273,22 @@ function playbackInterceptor({
|
|
|
273
273
|
function continueWithResponseBody(rawBody) {
|
|
274
274
|
prepareResponseHeaders(rawBody)
|
|
275
275
|
const bodyAsStream = convertBodyToStream(rawBody)
|
|
276
|
-
|
|
277
|
-
// so force flowing mode here. `delayBody` gates only the end-of-response
|
|
278
|
-
// signal below; a slow body must present as a slow body — read timeouts
|
|
279
|
-
// on the response can fire — instead of as a slow connection.
|
|
280
|
-
bodyAsStream.resume()
|
|
276
|
+
bodyAsStream.pause()
|
|
281
277
|
|
|
282
278
|
// IncomingMessage extends Readable so we can't simply pipe.
|
|
283
279
|
bodyAsStream.on('data', function (chunk) {
|
|
284
280
|
response.push(chunk)
|
|
285
281
|
})
|
|
286
|
-
bodyAsStream.on('
|
|
287
|
-
response.emit('error', err)
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
function emitEnd() {
|
|
282
|
+
bodyAsStream.on('end', function () {
|
|
291
283
|
// https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_message_complete
|
|
292
284
|
response.complete = true
|
|
293
285
|
response.push(null)
|
|
294
286
|
|
|
295
287
|
interceptor.scope.emit('replied', req, interceptor)
|
|
296
|
-
}
|
|
288
|
+
})
|
|
289
|
+
bodyAsStream.on('error', function (err) {
|
|
290
|
+
response.emit('error', err)
|
|
291
|
+
})
|
|
297
292
|
|
|
298
293
|
const { delayBodyInMs, delayConnectionInMs } = interceptor
|
|
299
294
|
|
|
@@ -311,17 +306,7 @@ function playbackInterceptor({
|
|
|
311
306
|
logger('emitting response')
|
|
312
307
|
req.emit('response', response)
|
|
313
308
|
|
|
314
|
-
|
|
315
|
-
// and the body source has finished, so `delay({ head, body })`
|
|
316
|
-
// compounds the two waits.
|
|
317
|
-
function scheduleEnd() {
|
|
318
|
-
common.setTimeout(emitEnd, delayBodyInMs)
|
|
319
|
-
}
|
|
320
|
-
if (bodyAsStream.readableEnded) {
|
|
321
|
-
scheduleEnd()
|
|
322
|
-
} else {
|
|
323
|
-
bodyAsStream.once('end', scheduleEnd)
|
|
324
|
-
}
|
|
309
|
+
common.setTimeout(() => bodyAsStream.resume(), delayBodyInMs)
|
|
325
310
|
}
|
|
326
311
|
|
|
327
312
|
socket.applyDelay(delayConnectionInMs)
|