simple-get
Advanced tools
Comparing version 1.4.1 to 1.4.2
16
index.js
@@ -14,11 +14,5 @@ module.exports = simpleGet | ||
// Follow redirects | ||
if (opts.maxRedirects === 0) { | ||
cb(new Error('too many redirects')) | ||
return | ||
} | ||
if (!opts.maxRedirects) opts.maxRedirects = 10 | ||
if (opts.url) parseOptsUrl(opts) | ||
if (!opts.headers) opts.headers = {} | ||
if (opts.headers == null) opts.headers = {} | ||
if (opts.maxRedirects == null) opts.maxRedirects = 10 | ||
@@ -43,4 +37,8 @@ var body = opts.body | ||
res.resume() // Discard response | ||
opts.maxRedirects -= 1 | ||
return simpleGet(opts, cb) | ||
if (opts.maxRedirects > 0) simpleGet(opts, cb) | ||
else cb(new Error('too many redirects')) | ||
return | ||
} | ||
@@ -47,0 +45,0 @@ |
{ | ||
"name": "simple-get", | ||
"description": "Simplest way to make http get requests. Supports HTTPS, redirects, gzip/deflate, streams in < 100 lines.", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Feross Aboukhadijeh", |
@@ -65,2 +65,25 @@ var concat = require('concat-stream') | ||
test('do not follow redirects', function (t) { | ||
t.plan(2) | ||
var server = http.createServer(function (req, res) { | ||
t.equal(req.url, '/1', 'visited /1') | ||
res.statusCode = 301 | ||
res.setHeader('Location', '/2') | ||
res.end() | ||
}) | ||
server.listen(0, function () { | ||
var port = server.address().port | ||
get({ | ||
url: 'http://localhost:' + port + '/1', | ||
maxRedirects: 0 | ||
}, function (err) { | ||
t.ok(err instanceof Error, 'got error') | ||
server.close() | ||
}) | ||
}) | ||
}) | ||
test('follow redirects (11 is too many)', function (t) { | ||
@@ -67,0 +90,0 @@ t.plan(11) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16217
380