mirror of
https://github.com/TangentFoxy/lovebird.git
synced 2025-07-28 11:02:19 +00:00
Added request body parsing to .onConnect()
This commit is contained in:
11
lovebird.lua
11
lovebird.lua
@@ -247,8 +247,8 @@ function lovebird.onRequest(req, client)
|
|||||||
return head .. lovebird.buffer
|
return head .. lovebird.buffer
|
||||||
end
|
end
|
||||||
-- Handle input
|
-- Handle input
|
||||||
if req.body then
|
if req.parsedbody.input then
|
||||||
local str = unescape(req.body:match(".-=(.*)"))
|
local str = req.parsedbody.input
|
||||||
xpcall(function() assert(loadstring(str))() end, lovebird.onError)
|
xpcall(function() assert(loadstring(str))() end, lovebird.onError)
|
||||||
end
|
end
|
||||||
-- Generate page
|
-- Generate page
|
||||||
@@ -278,6 +278,13 @@ function lovebird.onConnect(client)
|
|||||||
if req.headers["Content-Length"] then
|
if req.headers["Content-Length"] then
|
||||||
req.body = client:receive(req.headers["Content-Length"])
|
req.body = client:receive(req.headers["Content-Length"])
|
||||||
end
|
end
|
||||||
|
-- Parse body
|
||||||
|
req.parsedbody = {}
|
||||||
|
if req.body then
|
||||||
|
for k, v in req.body:gmatch("([^&]-)=([^&^#]*)") do
|
||||||
|
req.parsedbody[k] = unescape(v)
|
||||||
|
end
|
||||||
|
end
|
||||||
-- Parse request line's url
|
-- Parse request line's url
|
||||||
req.parsedurl = lovebird.parseurl(req.url)
|
req.parsedurl = lovebird.parseurl(req.url)
|
||||||
-- Handle request; get data to send
|
-- Handle request; get data to send
|
||||||
|
Reference in New Issue
Block a user