mirror of
https://github.com/koreader/koreader
synced 2024-11-11 19:11:14 +00:00
d7faba5b5c
and error should be checked in the callback
31 lines
880 B
Lua
31 lines
880 B
Lua
require("commonrequire")
|
|
local UIManager = require("ui/uimanager")
|
|
local HTTPClient = require("httpclient")
|
|
local DEBUG = require("dbg")
|
|
--DEBUG:turnOn()
|
|
|
|
describe("HTTP client module", function()
|
|
local requests = 0
|
|
local function response_callback(res)
|
|
requests = requests - 1
|
|
if requests == 0 then UIManager:quit() end
|
|
assert(not res.error, "error occurs")
|
|
assert(res.body)
|
|
end
|
|
local async_client = HTTPClient:new()
|
|
it("should get response from async GET request", function()
|
|
UIManager:quit()
|
|
local urls = {
|
|
"http://www.example.com",
|
|
"http://www.example.org",
|
|
}
|
|
requests = #urls
|
|
for _, url in ipairs(urls) do
|
|
async_client:request({
|
|
url = url,
|
|
}, response_callback)
|
|
end
|
|
UIManager:runForever()
|
|
end)
|
|
end)
|