@@ -91,34 +91,32 @@ module.exports = function (options) {
91
91
} ;
92
92
93
93
// 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 ;
95
96
96
97
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 ) ;
108
102
} ;
109
103
110
104
// Manage to get information from the response too, just like Connect.logger does:
111
- var end = res . end ;
105
+ res . _mo_end = res . end ;
112
106
113
107
res . end = function ( chunk , encoding , callback ) {
114
- // console.log('res end is invoked');
108
+
115
109
res . time = new Date ( ) ;
116
110
res . responseTime = ( new Date ) - req . _startTime ;
117
111
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 ;
119
117
res . end ( chunk , encoding , callback ) ;
120
118
121
- logEvent ( chunk , req , res , options , moesifController ) ;
119
+ logEvent ( resBodyBuf , req , res , options , moesifController ) ;
122
120
} ;
123
121
124
122
next ( ) ;
0 commit comments