Skip to content

Commit 42a6ce5

Browse files
committed
Fix: Ensure we capture all chunks if multiple when using node-http-proxy
1 parent 9e395b6 commit 42a6ce5

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

lib/index.js

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,34 +91,32 @@ module.exports = function (options) {
9191
};
9292

9393
// Manage to get information from the response too, just like Connect.logger does:
94-
var write = res.write;
94+
res._mo_write = res.write;
95+
var resBodyBuf;
9596

9697
res.write = function (chunk, encoding, callback) {
97-
// console.log('res write is invoked');
98-
99-
res.time = new Date();
100-
res.responseTime = (new Date) - req._startTime;
101-
102-
res.write = write;
103-
res.write(chunk, encoding, callback);
104-
105-
106-
logEvent(chunk, req, res, options, moesifController);
107-
98+
if (chunk) {
99+
resBodyBuf = resBodyBuf ? Buffer.concat([resBodyBuf, Buffer.from(chunk)]) : Buffer.from(chunk);
100+
}
101+
res._mo_write(chunk, encoding, callback);
108102
};
109103

110104
// Manage to get information from the response too, just like Connect.logger does:
111-
var end = res.end;
105+
res._mo_end = res.end;
112106

113107
res.end = function (chunk, encoding, callback) {
114-
// console.log('res end is invoked');
108+
115109
res.time = new Date();
116110
res.responseTime = (new Date) - req._startTime;
117111

118-
res.end = end;
112+
if (chunk) {
113+
resBodyBuf = resBodyBuf ? Buffer.concat([resBodyBuf, Buffer.from(chunk)]) : Buffer.from(chunk);
114+
}
115+
116+
res.end = res._mo_end;
119117
res.end(chunk, encoding, callback);
120118

121-
logEvent(chunk, req, res, options, moesifController);
119+
logEvent(resBodyBuf, req, res, options, moesifController);
122120
};
123121

124122
next();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "moesif-express",
3-
"version": "2.3.4",
3+
"version": "2.3.5",
44
"description": "Collection/Data Ingestion Middleware for Express",
55
"main": "./lib/index.js",
66
"keywords": [

0 commit comments

Comments
 (0)