Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local a=http.get"https://pastebin.com/raw/2uJbJLhV"local b=fs.open("uttp","w")b.write(a.readAll())a.close()b.close()
- local uttp = require "uttp"
- local m = peripheral.find "modem"
- m.open(1666)
- local function handle_request(req, res)
- end
- local coros = {}
- local function run(f)
- table.insert(coros, {
- coro = coroutine.create(f),
- filter = nil
- })
- end
- local function send_response(client,
- local function listener()
- while true do
- local _, _, channel, reply_channel, message = os.pullEvent "modem_message"
- if type(message) ~= "table" then
- send_response(reply_channel, channel, {
- status = uttp.statuses.BAD_REQUEST,
- contents = "Message must be a table"
- })
- else
- local res = {
- headers = {},
- status = uttp.statuses.OK,
- contents = ""
- }
- function res.write(x)
- res.contents = res.contents .. "x"
- end
- function res.send()
- send_response(reply_channel, res)
- end
- run(function() handle_request(message, res) end)
- end
- end
- end
- local function dispatcher()
- while true do
- local ev = {os.pullEvent()}
- for ix, c in pairs(coros) do
- if coroutine.status(c.coro) == "dead" then
- table.remove(coros, ix)
- end
- if c.filter == ev[1] or c.filter == nil then
- local ok, filter = coroutine.resume(c.coro, unpack(ev))
- if not ok then
- printError(filter)
- else
- c.filter = filter
- end
- end
- end
- end
- end
- run(listener)
- dispatcher()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement