Actually I spoke too soon. You can do this with the inject resolver, but it's going to be complicated. In general, the inject resolver is used to support extending mountebank with good ideas that I simply never thought about to buy time to implement those good ideas in an easier way.
The inject documentation demonstrates creating a proxy:
http://www.mbtest.org/docs/api/injection. The function, copied and slightly modified from the docs, should come close to what you want; it will behave similarly to a proxyOnce proxy:
function (request, state, logger, callback) {
var cacheKey = request.method + ' ' + request.path;
if (typeof state.requests === 'undefined') {
state.requests = {};
}
if (state.requests[cacheKey]) {
callback(state.requests[cacheKey]);
}
var http = require('http'),
options = {
method: request.method,
hostname: 'localhost',
port: 5555,
path: request.path,
headers: request.headers
},
httpRequest = http.request(options, function (response) {
var body = '';
response.setEncoding('utf8');
response.on('data', function (chunk) {
body += chunk;
});
response.on('end', function () {
var stubResponse = {
statusCode: response.statusCode,
headers: response.headers,
body: body
};
// Add custom header
stubResponse.headers['X-Custom'] = 'Testing...'
logger.info('Successfully proxied: ' + JSON.stringify(stubResponse));
state.requests[cacheKey] = stubResponse;
callback(stubResponse);
});
});
httpRequest.end();
}