From e14629329f64f01073383398aac311ea27fbe32f Mon Sep 17 00:00:00 2001 From: onefang Date: Sun, 29 Sep 2019 12:25:45 +1000 Subject: checkURL -> checkHEAD --- README.md | 6 +++--- mirror-checker.lua | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index a411e29..7ac867b 100644 --- a/README.md +++ b/README.md @@ -246,13 +246,13 @@ includes the IP this time. The inclusion of the IP causes checkRedirects() to call checkPaths(). -checkPaths() will call checkURL() for each of the reference files. +checkPaths() will call checkHEAD() for each of the reference files. -checkURL() uses LuaSocket (or LuaSec for HTTPS) to send a HEAD request to +checkHEAD() uses LuaSocket (or LuaSec for HTTPS) to send a HEAD request to the IP, with a Host header set to the original host name. Redirects will not be followed by that request. If the request returns a redirect, then -checkURL() is called recursively. If the redirect is to some host we are +checkHEAD() is called recursively. If the redirect is to some host we are not already checking, we call checkRedirects() on it, with an IP of "redir". This causes checkRedirects() to bypass the test that would otherwise call checkPaths(), instead gathering the IPs and fork as usual. diff --git a/mirror-checker.lua b/mirror-checker.lua index b2d1cc7..23c7e33 100755 --- a/mirror-checker.lua +++ b/mirror-checker.lua @@ -197,7 +197,7 @@ local nlst = function (u) return r and table.concat(t), e end -checkURL = function (host, URL, r, retry) +checkHEAD = function (host, URL, r, retry) if nil == r then r = 0 end if nil == retry then retry = 0 end local check = "Checking file" @@ -249,7 +249,7 @@ checkURL = function (host, URL, r, retry) E(" " .. c .. " " .. s .. "! " .. check .. " " .. host .. " -> " .. URL) -- So far the only errors are "timeout", "Network is unreachable", and "closed", and I suspect "closed" is due to saturating my bandwidth. -- Might be worthwhile retrying those, some number of times. - if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkURL(host, URL, r, retry + 1) end + if ("closed" == c) or ("Network is unreachable" == c) or ("timeout" == c) then checkHEAD(host, URL, r, retry + 1) end else if ("4" == tostring(c):sub(1, 1)) or ("5" == tostring(c):sub(1, 1)) then E(" " .. c .. " " .. s .. ". " .. check .. " " .. host .. " -> " .. URL) @@ -267,9 +267,9 @@ checkURL = function (host, URL, r, retry) E(" redirect loop! " .. check .. " " .. host .. " -> " .. URL) elseif nil == pu.host then W(" no location host! " .. check .. " " .. host .. " -> " .. URL .. " -> " .. l) - checkURL(host, PU.scheme .. "://" .. PU.host .. l, r + 1) + checkHEAD(host, PU.scheme .. "://" .. PU.host .. l, r + 1) else - checkURL(pu.host, l, r + 1) + checkHEAD(pu.host, l, r + 1) end end end @@ -279,20 +279,20 @@ local checkPaths = function (host, ip, path, file) if nil ~= file then if "redirect" == ip then ip = host end I(" Checking IP for file " .. host .. " -> " .. ip .. " " .. path .. " " .. file) - if testing("http", host) then checkURL(host, "http://" .. ip .. path .. "/" .. file) end - if testing("https", host) then checkURL(host, "https://" .. ip .. path .. "/" .. file) end + if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. file) end + if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. file) end else I(" Checking IP " .. host .. " -> " .. ip .. " " .. path) for i, s in pairs(referenceDevs) do - if testing("http", host) then checkURL(host, "http://" .. ip .. path .. "/" .. s) end - if testing("https", host) then checkURL(host, "https://" .. ip .. path .. "/" .. s) end + if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/" .. s) end + if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/" .. s) end end for i, s in pairs(releases) do for j, k in pairs(releaseFiles) do if repoExists(s .. k) then - if testing("http", host) then checkURL(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end - if testing("https", host) then checkURL(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end + if testing("http", host) then checkHEAD(host, "http://" .. ip .. path .. "/merged/dists/" .. s .. k) end + if testing("https", host) then checkHEAD(host, "https://" .. ip .. path .. "/merged/dists/" .. s .. k) end end end end @@ -308,9 +308,9 @@ checkRedirects = function (orig, host, path, ip, file) if nil == host then host = orig end if nil == path then path = "" end if nil == file then file = "" end - local po = url.parse("http://" .. orig) local ph = url.parse("http://" .. host) if (nil ~= ip) and ("redir" ~= ip) then + local po = url.parse("http://" .. orig) if "" ~= file then D("checking redirected file " .. po.host .. " " .. file) checkPaths(po.host, ip, path, file) -- cgit v1.1