Adding a check to ensure res._header is set before checking values

This commit is contained in:
Chris Cowan 2015-02-06 16:51:09 -07:00
parent 02fbd17680
commit f42d51a514

View file

@ -7,7 +7,10 @@ module.exports = function (options) {
var _req = _.pick(req, ['url', 'headers', 'method']);
_req.connection = _.pick(req.connection, ['remoteAddress', 'remotePort']);
res.end = function (chunk, encoding) {
var contentLength = parseInt(res._header['content-length'], 10);
var contentLength = 0;
if (res._header && res._header['content-length']) {
contentLength = parseInt(res._header['content-length'], 10);
}
res.responseTime = (new Date()).getTime() - startTime.getTime();
res.contentLength = isNaN(contentLength) ? 0 : contentLength;
end.call(res, chunk, encoding);