Allow 2 redirects

This commit is contained in:
calzoneman 2015-05-25 16:04:27 -04:00
parent 9b3a71d84f
commit a81f691d4e

View file

@ -25,7 +25,8 @@ var audioOnlyContainers = {
"mp3": true
};
function testUrl(url, cb, redirected) {
function testUrl(url, cb, redirCount) {
if (!redirCount) redirCount = 0;
var data = urlparse.parse(url);
if (!/https?:/.test(data.protocol)) {
return cb("Video links must start with http:// or https://");
@ -41,11 +42,11 @@ function testUrl(url, cb, redirected) {
req.abort();
if (res.statusCode === 301 || res.statusCode === 302) {
if (redirected) {
if (redirCount > 2) {
return cb("Too many redirects. Please provide a direct link to the " +
"file");
}
return testUrl(res.headers['location'], cb, true);
return testUrl(res.headers['location'], cb, redirCount + 1);
}
if (res.statusCode !== 200) {