clean up, but example does not work at this time

This commit is contained in:
Marcos Kirsch 2016-02-15 22:54:19 -06:00
parent 2f2fb26782
commit d71b079932

View File

@ -1,32 +1,28 @@
return function (connection, req, args) return function (connection, req, args)
connection:send("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nCache-Control: private, no-store\r\n\r\n") dofile("httpserver-header.lc")(connection, 200, 'html')
connection:send('<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Arguments</title></head>') connection:send([===[
connection:send('<body>') <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>Arguments by POST</title></head><body><h1>Arguments by POST</h1>
connection:send('<h1>Arguments</h1>') ]===])
local form = [===[ if req.method == "GET" then
connection:send([===[
<form method="POST"> <form method="POST">
First name:<br><input type="text" name="firstName"><br> First name:<br><input type="text" name="firstName"><br>
Last name:<br><input type="text" name="lastName"><br> Last name:<br><input type="text" name="lastName"><br>
<input type="radio" name="sex" value="male" checked>Male<input type="radio" name="sex" value="female">Female<br> <input type="radio" name="sex" value="male" checked>Male<input type="radio" name="sex" value="female">Female<br>
<input type="submit" value="Submit"> <input type="submit" name="submit" value="Submit">
</form> </form>
]===] ]===])
if req.method == "GET" then
connection:send(form)
elseif req.method == "POST" then elseif req.method == "POST" then
local rd = req.getRequestData() local rd = req.getRequestData()
-- connection:send(cjson.encode(rd))
connection:send('<h2>Received the following values:</h2>') connection:send('<h2>Received the following values:</h2>')
connection:send("<ul>\n") connection:send("<ul>\n")
for name, value in pairs(rd) do for name, value in pairs(rd) do
connection:send('<li><b>' .. name .. ':</b> ' .. tostring(value) .. "<br></li>\n") connection:send('<li><b>' .. name .. ':</b> ' .. tostring(value) .. "<br></li>\n")
end end
connection:send("</ul>\n") connection:send("</ul>\n")
else else
connection:send("NOT IMPLEMENTED") connection:send("ERROR WTF req.method is ", req.method)
end end
connection:send('</body></html>') connection:send('</body></html>')