2015-09-12 19:28:17 +00:00
|
|
|
describe("HTTP client module #notest #nocov", function()
|
2017-01-21 13:58:01 +00:00
|
|
|
local UIManager
|
|
|
|
setup(function()
|
|
|
|
require("commonrequire")
|
|
|
|
UIManager = require("ui/uimanager")
|
2022-09-27 23:10:50 +00:00
|
|
|
-- Set true to test httpclient
|
|
|
|
G_defaults:makeFalse("DUSE_TURBO_LIB")
|
|
|
|
end)
|
|
|
|
teardown(function()
|
|
|
|
G_defaults:delSetting("DUSE_TURBO_LIB")
|
2017-01-21 13:58:01 +00:00
|
|
|
end)
|
|
|
|
|
2015-03-02 09:15:26 +00:00
|
|
|
local requests = 0
|
|
|
|
local function response_callback(res)
|
|
|
|
requests = requests - 1
|
|
|
|
if requests == 0 then UIManager:quit() end
|
2015-03-07 03:19:39 +00:00
|
|
|
assert(not res.error, "error occurs")
|
2015-03-02 09:15:26 +00:00
|
|
|
assert(res.body)
|
|
|
|
end
|
2017-01-21 13:58:01 +00:00
|
|
|
|
2015-03-02 09:15:26 +00:00
|
|
|
it("should get response from async GET request", function()
|
2015-10-07 15:00:49 +00:00
|
|
|
local HTTPClient = require("httpclient")
|
|
|
|
local async_client = HTTPClient:new()
|
2015-03-02 09:15:26 +00:00
|
|
|
UIManager:quit()
|
|
|
|
local urls = {
|
|
|
|
"http://www.example.com",
|
|
|
|
"http://www.example.org",
|
2015-04-28 03:06:00 +00:00
|
|
|
"http://www.example.net",
|
|
|
|
"https://www.example.com",
|
|
|
|
"https://www.example.org",
|
2015-03-02 09:15:26 +00:00
|
|
|
}
|
|
|
|
requests = #urls
|
|
|
|
for _, url in ipairs(urls) do
|
|
|
|
async_client:request({
|
|
|
|
url = url,
|
2015-03-07 03:19:39 +00:00
|
|
|
}, response_callback)
|
2015-03-02 09:15:26 +00:00
|
|
|
end
|
2022-10-27 20:08:38 +00:00
|
|
|
UIManager:setRunForeverMode()
|
|
|
|
UIManager:run()
|
2015-03-02 09:15:26 +00:00
|
|
|
end)
|
|
|
|
end)
|