examples: add example Lua handler script
[project/uhttpd.git] / examples / lua / handler.lua
1 function handle_request(env)
2 uhttpd.send("Status: 200 OK\r\n")
3 uhttpd.send("Content-Type: text/html\r\n\r\n")
4
5 uhttpd.send("<h1>Headers</h1>\n")
6 for k, v in pairs(env.headers) do
7 uhttpd.send(string.format("<strong>%s</strong>: %s<br>\n", k, v))
8 end
9
10 uhttpd.send("<h1>Environment</h1>\n")
11 for k, v in pairs(env) do
12 if type(v) == "string" then
13 uhttpd.send(string.format("<code>%s=%s</code><br>\n", k, v))
14 end
15 end
16 end