From e0ee8e9ad023636d58733b5255098d1fff35f960 Mon Sep 17 00:00:00 2001 From: Ale32bit Date: Fri, 1 Apr 2016 15:22:44 +0200 Subject: [PATCH] Create shttp.lua --- src/apis/shttp.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/apis/shttp.lua diff --git a/src/apis/shttp.lua b/src/apis/shttp.lua new file mode 100644 index 0000000..40c1c07 --- /dev/null +++ b/src/apis/shttp.lua @@ -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