Path: blob/master/src/middlewares/bodyDataInterceptor.js
115 views
const StreamWriter = require('./utils/StreamWriter');12module.exports = function validateCache() {3return function bodyDataInterceptor(req, res, next) {4if (req.mock.mockExists) {5next();6return;7}8const oldWrite = res.write;9const oldEnd = res.end;1011const ws = new StreamWriter();12res.bodyStream = ws;1314res.write = function (chunk) {15ws.write(chunk);16oldWrite.apply(res, arguments);17};18res.end = function (chunk) {19ws.end(chunk);20oldEnd.apply(res, arguments);21};2223next();24};25};262728