Discard response before throw
@ -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;
}
get(urlLib.resolve(url, res.headers.location), opts, cb);
@ -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();