2018-01-31 11:39:04 +00:00
|
|
|
local logger = require("logger")
|
|
|
|
local http_request = require "http.request"
|
|
|
|
|
|
|
|
-- Currently unused. TODO @mwoz123 ADD LUA-HTTP AS LIBRARY
|
|
|
|
local LuaHttpDownloadBackend = {}
|
|
|
|
|
|
|
|
function LuaHttpDownloadBackend:getResponseAsString(url)
|
|
|
|
local _, stream = assert(http_request.new_from_uri(url):go())
|
|
|
|
local body = assert(stream:get_body_as_string())
|
2022-09-16 22:08:00 +00:00
|
|
|
logger.dbg("Response body:", body)
|
2018-01-31 11:39:04 +00:00
|
|
|
return body
|
|
|
|
end
|
|
|
|
|
|
|
|
function LuaHttpDownloadBackend:download(link, path)
|
|
|
|
local _, stream = assert(http_request.new_from_uri(link):go())
|
|
|
|
stream:save_body_to_file(path)
|
|
|
|
stream:shutdown()
|
|
|
|
end
|
|
|
|
|
|
|
|
return LuaHttpDownloadBackend
|