Added request body parsing to .onConnect()

This commit is contained in:
rxi 2014-04-11 20:27:09 +01:00
parent 4df9d773eb
commit e80439e883

View File

@ -247,8 +247,8 @@ function lovebird.onRequest(req, client)
return head .. lovebird.buffer
end
-- Handle input
if req.body then
local str = unescape(req.body:match(".-=(.*)"))
if req.parsedbody.input then
local str = req.parsedbody.input
xpcall(function() assert(loadstring(str))() end, lovebird.onError)
end
-- Generate page
@ -278,6 +278,13 @@ function lovebird.onConnect(client)
if req.headers["Content-Length"] then
req.body = client:receive(req.headers["Content-Length"])
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
req.parsedurl = lovebird.parseurl(req.url)
-- Handle request; get data to send