fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
7e0ab3b
v2.1.3
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 12local demand =requests_channel : demand () 13 14if demand == false then break end 15 16local id , request =demand . id , demand . request 17 18-- create a table to store the results 19local result_table ={} 20request . sink =ltn12 . sink . table ( result_table ) 21 22if request . body then 23request . source =ltn12 . source . string ( request . body ) 24end 25 26-- Get code, and header response 27local status , code , header =https . request ( request ) 28 29if status then 30-- request was successful 31progress_channel : push ( { id =id , event ={ success =true , response =table . concat ( result_table ), code =code , header =header }} ) 32else 33-- in case of failure, the error message is stored in the second return value 34progress_channel : push ( { id =id , event ={ success =false , error =code }} ) 35end 36end