--------------------------------------------------------- --- ClientHTTP library for ZD --------------------------------------------------------- local http = require("http") local https = require("https") return function(ZD) ZD.requestGET = function(host, port, path, cb, headers) local output = "" if not headers then headers = {} end headers["User-Agent"] = headers["User-Agent"] or "ZED/0.0.9 (luvit.io-master)" local req = http.request({host = host,port = port,path = path, headers = headers}, function (res) res:on("error", function(err) cb(tostring(err)) end) res:on("data", function (chunk) output = output .. chunk end) res:on("end", function () res:destroy() cb(nil, output) end) end) req:on("error", function(err) cb(tostring(err)) end) req:done() end ZD.requestSGET = function(host, port, path, cb, headers) local output = "" if not headers then headers = {} end headers["User-Agent"] = headers["User-Agent"] or "ZED/0.0.9 (luvit.io-master)" local req = https.request({host = host, port = port, path = path, headers = headers}, function (res) res:on("error", function(err) cb(tostring(err)) end) res:on("data", function (chunk) output = output .. chunk end) res:on("end", function () res:destroy() cb(nil, output) end) end) req:on("error", function(err) cb(tostring(err)) end) req:done() end end