Create shttp.lua
This commit is contained in:
parent
3f154bbfe1
commit
e0ee8e9ad0
1 changed files with 24 additions and 0 deletions
24
src/apis/shttp.lua
Normal file
24
src/apis/shttp.lua
Normal file
|
@ -0,0 +1,24 @@
|
|||
function get(url, post, header, timeout)
|
||||
if not url then
|
||||
error("a nil value",2)
|
||||
end
|
||||
if not timeout or not tonumber(timeout) then
|
||||
timeout = 1
|
||||
end
|
||||
|
||||
http.request(url, post, header)
|
||||
|
||||
while true do
|
||||
local timer = os.startTimer(timeout)
|
||||
local ev = {os.pullEvent()}
|
||||
if ev[1] == "timer" and ev[2] == timer then
|
||||
return false, nil, nil --ikr...
|
||||
elseif ev[1] == "http_success" then
|
||||
local source = ev[3].readAll()
|
||||
ev[3].close()
|
||||
return true, source, ev[2]
|
||||
elseif ev[1] == "http_failure" then
|
||||
return false, nil, ev[2]
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue