LiquidProxy Lua Edition
at master 56 lines 1.3 kB view raw
1local uverrs = require "app.uverrs" 2 3---@type luvit.http 4local http = require "http" 5 6return function (req, res) 7 local proto = req.path:match("^(%S+)://") 8 if proto ~= "ws" and proto ~= "http" then 9 res.statusCode = 400 10 local rs = "Bad protocol" 11 res:setHeader("Content-Length", tostring(#rs)) 12 res:finish(rs) 13 return 14 end 15 local dom, port = req.path:match("://(%S+):?(%d)*/") 16 local path = req.path:match("://%S+(/.+)$") 17 local opts = { 18 headers = req.headers, 19 host = dom, 20 method = req.method, 21 path = path, 22 port = port or 80 23 } 24 25 local c = http.request(opts, function(cres) 26 res.headers = cres.headers 27 res.statusCode = cres.statusCode 28 cres:pipe(res) 29 end) 30 31 c:done() 32 local suc = true 33 local rs = "hi" 34 if suc then 35 ---@diagnostic disable-next-line: param-type-mismatch 36 --[[for k, v in pairs(rs) do 37 if tonumber(k) then 38 res.headers[k] = v 39 else 40 res[k] = v 41 end 42 end 43 p(req) 44 local c = r:get("Connection") 45 if c then 46 --res: 47 end 48 res:finish(body)]] 49 else 50 res.statusCode = 502 51 local et = "LiquidProxy: "..(uverrs[rs] or rs).."\r\n" 52 res:setHeader("Content-Type", "text/plain") 53 res:setHeader("Content-Length", tostring(et:len())) 54 res:finish(et) 55 end 56end