examples: add example Lua handler script
authorJo-Philipp Wich <jo@mein.io>
Tue, 23 Nov 2021 18:21:58 +0000 (19:21 +0100)
committerJo-Philipp Wich <jo@mein.io>
Tue, 23 Nov 2021 18:26:43 +0000 (19:26 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
examples/lua/handler.lua [new file with mode: 0644]

diff --git a/examples/lua/handler.lua b/examples/lua/handler.lua
new file mode 100644 (file)
index 0000000..dbcea4a
--- /dev/null
@@ -0,0 +1,16 @@
+function handle_request(env)
+       uhttpd.send("Status: 200 OK\r\n")
+       uhttpd.send("Content-Type: text/html\r\n\r\n")
+
+       uhttpd.send("<h1>Headers</h1>\n")
+       for k, v in pairs(env.headers) do
+               uhttpd.send(string.format("<strong>%s</strong>: %s<br>\n", k, v))
+       end
+
+       uhttpd.send("<h1>Environment</h1>\n")
+       for k, v in pairs(env) do
+               if type(v) == "string" then
+                       uhttpd.send(string.format("<code>%s=%s</code><br>\n", k, v))
+               end
+       end
+end