You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

37 lines
1.1 KiB

local UIManager = require("ui/uimanager")
local HTTPClient = {
input_timeouts = 0,
}
function HTTPClient:new()
local o = {}
setmetatable(o, self)
self.__index = self
return o
end
function HTTPClient:request(request, response_callback)
request.connect_timeout = 10
request.request_timeout = 20
UIManager:initLooper()
UIManager.looper:add_callback(function()
-- avoid endless waiting for input
UIManager:setInputTimeout()
self.input_timeouts = self.input_timeouts + 1
local turbo = require("turbo")
-- disable success and warning logs
turbo.log.categories.success = false
turbo.log.categories.warning = false
local client = turbo.async.HTTPClient({verify_ca = false})
local res = coroutine.yield(client:fetch(request.url, request))
self.input_timeouts = self.input_timeouts - 1
-- reset INPUT_TIMEOUT to nil when all HTTP requests are fullfilled.
if self.input_timeouts == 0 then UIManager:resetInputTimeout() end
if response_callback then
response_callback(res)
end
end)
end
return HTTPClient