From c9fc01638e8a8d62e9057aec70ef8fe40b53c74f Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 29 Sep 2019 14:19:11 +1000 Subject: Rejig the redirects a little. --- mirror-checker.lua | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'mirror-checker.lua') diff --git a/mirror-checker.lua b/mirror-checker.lua index 81b32db..34d1023 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua @@ -203,29 +203,12 @@ checkHEAD = function (host, URL, r, retry) local check = "Checking file" if 0 < r then check = "Redirecting to" - --[[ The hard part here is that we end up throwing ALL of the test files at the redirected location. - Not good for deb.debian.org, which we should only be throwing .debs at. - What we should do is loop through the DNS entries, and only test the specific protocol & file being tested here. - - This is what I came up with for checking if we are already testing a specific URL. - Still duplicates a tiny bit, but much less than the previous find based method. - ]] - local pl = url.parse(URL, defaultURL) - local file = host .. "://" .. pl.path - local f = io.popen(string.format('if [ ! -f results/%s.check ] ; then touch results/%s.check; echo -n "check"; fi', file:gsub("/", "_"), file:gsub("/", "_") )):read("*a") - if (nil == f) or ("check" == f) then - I(" Now checking redirected host " .. file) - checkHost(host, host, nil, "redir", pl.path) - else - D(" Already checking " .. file) - end - end if 0 < retry then -- TODO - should have a random sleep here before retrying. check = "Retry " .. retry .. " " .. check end - if 10 < r then + if 20 < r then E("too many redirects! " .. check .. " " .. host .. " -> " .. URL) return end @@ -242,6 +225,7 @@ checkHEAD = function (host, URL, r, retry) local htp = http; if PU.scheme == "https" then htp = https end -- NOTE - the docs for lua-sec say that redirect isn't supported is version 0.6, no idea if that means it ignores redirections like we want. + -- TODO - find out! -- The protocol and options are lua-sec specific arguments. local p, c, h, s = htp.request{method = "HEAD", redirect = false, url = URL, headers = hd, protocol = "any", options = "all"} if nil == s then s = "" end @@ -259,17 +243,33 @@ checkHEAD = function (host, URL, r, retry) l = h.location if nil ~= l then local pu = url.parse(l, defaultURL) - if pu.scheme ~= PU.scheme then - if testing("Protocol") then - W(" protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) - end - elseif l == URL then + if testing("Protocol") and (pu.scheme ~= PU.scheme) then + W(" protocol changed during redirect! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) + end + + if l == URL then E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL) elseif nil == pu.host then - W(" no location host! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) + I(" relative redirect. " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) checkHEAD(host, PU.scheme .. "://" .. PU.host .. l, r + 1) - else + elseif PU.host == pu.host then checkHEAD(pu.host, l, r + 1) + else + --[[ The hard part here is that we end up throwing ALL of the test files at the redirected location. + Not good for deb.debian.org, which we should only be throwing .debs at. + What we do is loop through the DNS entries, and only test the specific protocol & file being tested here. + + This is what I came up with for checking if we are already testing a specific URL. + Still duplicates a tiny bit, but much less than the previous find based method. + ]] + local file = pu.host .. "://" .. pu.path + local f = io.popen(string.format('if [ ! -f results/%s.check ] ; then touch results/%s.check; echo -n "check"; fi', file:gsub("/", "_"), file:gsub("/", "_") )):read("*a") + if (nil == f) or ("check" == f) then + I(" Now checking redirected host " .. file) + checkHost(pu.host, pu.host, nil, "redir", pu.path) + else + D(" Already checking " .. file) + end end end end @@ -277,7 +277,7 @@ end local checkFiles = function (host, ip, path, file) if nil ~= file then - if "redirect" == ip then ip = host end + if "redir" == ip then ip = host end I(" Checking IP for file " .. host .. " -> " .. ip .. " " .. path .. " " .. file) if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. file) end if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. file) end -- cgit v1.1