aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorsinanmohd <sinan@sinanmohd.com>2023-10-04 08:54:28 +0530
committersinanmohd <sinan@sinanmohd.com>2023-10-04 08:54:28 +0530
commitf0d0eded1f9b7f2a244d414d09ad97e197601fab (patch)
tree49bf5024b16adb0140c6c30af9504306bbd55efd /lib
parent71f7b25ab3c8302972998714e98a5126cf1259e5 (diff)
lib/curl: move retry logic to curl from server
Diffstat (limited to 'lib')
-rw-r--r--lib/curl.lua31
1 files changed, 16 insertions, 15 deletions
diff --git a/lib/curl.lua b/lib/curl.lua
index 04ebf95..5272508 100644
--- a/lib/curl.lua
+++ b/lib/curl.lua
@@ -17,7 +17,7 @@ local head_to_args = function (t)
return args
end
-local get = function (url, headr, args)
+local get = function (url, headr, args, tries)
local fetch, hcode, def_args
def_args = {
@@ -35,28 +35,29 @@ local get = function (url, headr, args)
headr = util.table_merge(def_headr, headr)
args = util.array_merge(args, head_to_args(headr))
- fetch = util.run(args)
- -- hcode can be nil, it means curl was't able to fulfill the http request, either
- -- because curl package is broken or mpv killed it prematurely. we can exit
- -- out of retry loop early if hcode is nil since there's no point in retrying
- hcode = fetch:match('%d*$')
- fetch = fetch:gsub('%s*%d*$', '')
+ repeat
+ fetch = util.run(args)
+ -- hcode can be nil, it means curl was't able to fulfill the http request, either
+ -- because curl package is broken or mpv killed it prematurely. we can exit
+ -- out of retry loop early if hcode is nil since there's no point in retrying
+ hcode = fetch:match('%d*$')
+ tries = tries - 1
+ until hcode == '200' or not hcode or tries <= 0
+
+ fetch = fetch:gsub('%s*%d*$', '')
return fetch, tonumber(hcode)
end
-local zip_link_to_file = function (url, headr, out, retries)
- local tries, hcode, zip, rc
+local zip_link_to_file = function (url, headr, out, tries)
+ local hcode, zip, rc, args
- tries = 0
zip = os.tmpname()
+ args = { '-o'.. zip }
- repeat
- _, hcode = get(url, headr, { '-o'.. zip })
- tries = tries + 1
- until hcode == 200 or not hcode or tries > retries
- rc = (hcode == 200)
+ _, hcode = get(url, headr, args, tries)
+ rc = (hcode == 200)
if rc then
rc = util.zip_ext_first(zip, out)
end