in apps/mountebank-mock/mountebank-source/src/models/responseResolver.js [261:296]
async function proxyAndRecord (responseConfig, request, logger, requestDetails, imposterState) {
const startTime = new Date(),
observeProxyDuration = metrics.proxyDuration.startTimer();
metrics.proxyCount.inc({ imposter: logger.scopePrefix });
if (['proxyOnce', 'proxyAlways', 'proxyTransparent'].indexOf(responseConfig.proxy.mode) < 0) {
responseConfig.proxy.mode = 'proxyOnce';
}
if (inProcessProxy) {
const response = await proxy.to(responseConfig.proxy.to, request, responseConfig.proxy, requestDetails);
observeProxyDuration({ imposter: logger.scopePrefix });
response._proxyResponseTime = new Date() - startTime;
// Run behaviors here to persist decorated response
const transformed = await behaviors.execute(request, response, responseConfig.behaviors, logger, imposterState);
await recordProxyResponse(responseConfig, request, transformed, logger);
return transformed;
}
else {
pendingProxyResolutions[nextProxyResolutionKey] = {
responseConfig: responseConfig,
request: request,
requestDetails: requestDetails,
observeProxyDuration: observeProxyDuration,
startTime: startTime
};
nextProxyResolutionKey += 1;
return {
proxy: responseConfig.proxy,
request: request,
callbackURL: `${callbackURL}/${nextProxyResolutionKey - 1}`
};
}
}