mirror of
https://github.com/rxi/lovebird.git
synced 2024-11-15 22:54:21 +00:00
Added request body parsing to .onConnect()
This commit is contained in:
parent
4df9d773eb
commit
e80439e883
11
lovebird.lua
11
lovebird.lua
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user