fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

BkacjiosApplication update checker7e0ab3b

v2.1.3
1.1 KiB36 linesraw
1local https = require("https")
2--local http = require("socket.http")
3
4local ltn12 = require("ltn12")
5
6-- these two channels are used to send requests and progress updates back and forth
7local requests_channel = love.thread.getChannel("web-requests")
8local progress_channel = love.thread.getChannel("web-progress")
9
10while true do
11	-- wait for a request to arrive
12	local demand = requests_channel:demand()
13
14	if demand == false then break end
15
16	local id, request = demand.id, demand.request
17
18	-- create a table to store the results
19	local result_table = {}
20	request.sink = ltn12.sink.table(result_table)
21
22	if request.body then
23		request.source = ltn12.source.string(request.body)
24	end
25
26	-- Get code, and header response
27	local status, code, header = https.request(request)
28
29	if status then
30		-- request was successful
31		progress_channel:push({id=id, event={success=true, response=table.concat(result_table), code=code, header=header}})
32	else
33		-- in case of failure, the error message is stored in the second return value
34		progress_channel:push({id=id, event={success=false, error = code}})
35	end
36end