diff options
author | Jo-Philipp Wich <jo@mein.io> | 2021-11-23 19:21:58 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2021-11-23 19:26:43 +0100 |
commit | f0f14068f34adb6c9145e1c58786f2f9c805e4ee (patch) | |
tree | 8273c409ac6bbaa154114303d01de4ec0dfee65c | |
parent | 9e87095a4125b0bf45eac95d00d528153b0c4310 (diff) |
examples: add example Lua handler script
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | examples/lua/handler.lua | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/examples/lua/handler.lua b/examples/lua/handler.lua new file mode 100644 index 0000000..dbcea4a --- /dev/null +++ b/examples/lua/handler.lua @@ -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 |