Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
akupiec
GitHub Repository: akupiec/mad-proxy
Path: blob/master/src/middlewares/bodyDataInterceptor.js
115 views
1
const StreamWriter = require('./utils/StreamWriter');
2
3
module.exports = function validateCache() {
4
return function bodyDataInterceptor(req, res, next) {
5
if (req.mock.mockExists) {
6
next();
7
return;
8
}
9
const oldWrite = res.write;
10
const oldEnd = res.end;
11
12
const ws = new StreamWriter();
13
res.bodyStream = ws;
14
15
res.write = function (chunk) {
16
ws.write(chunk);
17
oldWrite.apply(res, arguments);
18
};
19
res.end = function (chunk) {
20
ws.end(chunk);
21
oldEnd.apply(res, arguments);
22
};
23
24
next();
25
};
26
};
27
28