-
Notifications
You must be signed in to change notification settings - Fork 10
Closed
Description
defaultHandler
will cause memory leak if user doesn't listens on response
event.
Possible fix:
var EventEmitter = require('events').EventEmitter;
function defaultHandler(request, options, cb) {
var url = (typeof options === 'string' ? urlParse(options) : options).href;
var start = new Date();
setImmediate(console.log, chalk.gray(' → ' + url));
var wasHandled = typeof cb === 'function';
return request(options, cb)
.once('response', function (response) {
var request = response.req;
if (!wasHandled && EventEmitter.listenerCount(request, 'response') === 0)
response.resume();
var status = response.statusCode;
var s = status / 100 | 0;
console.log(' ' + chalk[colorCodes[s]](status) + ' ← ' + url + ' ' + chalk.gray(time(start)));
})
.on('error', function (err) {
console.log(' ' + chalk.red('xxx') + ' ← ' + url + ' ' + chalk.red(err.message));
});
}
Metadata
Metadata
Assignees
Labels
No labels