Skip to content

Commit 93fe583

Browse files
committed
Fixed U.request() again.
1 parent c4cd139 commit 93fe583

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

utils.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ exports.request = function(url, flags, data, callback, cookies, headers, encodin
435435
timeout = encoding;
436436
}
437437

438+
if (callback === NOOP)
439+
callback = null;
440+
438441
var options = { length: 0, timeout: 10000, evt: new events.EventEmitter(), encoding: typeof(encoding) !== 'string' ? ENCODING : encoding, callback: callback, post: false, redirect: 0 };
439442
var method;
440443
var type = 0;
@@ -608,6 +611,12 @@ function request_response(res, uri, options) {
608611
if (options.redirect > 3) {
609612
if (options.callback)
610613
options.callback(new Error('Too many redirects.'), '', 0, undefined, uri.host);
614+
615+
if (options.evt) {
616+
options.evt.removeAllListeners();
617+
options.evt = null;
618+
}
619+
611620
res.req.removeAllListeners();
612621
res.req = null;
613622
res.removeAllListeners();
@@ -643,7 +652,7 @@ function request_response(res, uri, options) {
643652
}
644653

645654
options.length = +res.headers['content-length'] || 0;
646-
options.evt.emit('begin', options.length);
655+
options.evt && options.evt.emit('begin', options.length);
647656

648657
res.on('data', function(chunk) {
649658
var self = this;

0 commit comments

Comments
 (0)