diff --git a/index.js b/index.js index 446af8e..5e336c5 100644 --- a/index.js +++ b/index.js @@ -61,13 +61,13 @@ function got(url, opts, cb) { // redirect if (statusCode >= 300 && statusCode < 400 && 'location' in res.headers) { + res.resume(); // Discard response + if (++redirectCount > 10) { cb(new Error('Redirected 10 times. Aborting.'), undefined, res); return; } - res.resume(); // Discard response - get(urlLib.resolve(url, res.headers.location), opts, cb); return; } diff --git a/test/test-redirects.js b/test/test-redirects.js index c6cdc11..7fe18a2 100644 --- a/test/test-redirects.js +++ b/test/test-redirects.js @@ -54,7 +54,7 @@ tape('follows relative redirect', function (t) { }); tape('throws on endless redirect', function (t) { - got(s.url + '/endless', {agent: false}, function (err) { + got(s.url + '/endless', function (err) { t.ok(err, 'should get error'); t.equal(err.message, 'Redirected 10 times. Aborting.'); t.end();