mg.write("HTTP/1.0 200 OK\r\n")
mg.write("Content-Type: text/html\r\n")
mg.write("\r\n")
mg.write([[
This is another example of a Lua server page, served by
CivetWeb web server.
The following features are available:
]])
function print_if_available(tab, name)
  if tab then
    mg.write("- " .. name .. "\n")
  end
end
function recurse(tab, excl)
  excl = excl or {}
  mg.write("
\n")
  for k,v in pairs(tab) do
    if type(v) == "table" then
      mg.write("- " .. tostring(k) .. ":\n")
      if excl[v] then
        -- cyclic
      else
        excl[v] = true
        recurse(v, excl)
        excl[v] = false
      end
    else
      mg.write("
- " .. tostring(k) .. " = " .. tostring(v) .. "\n")
    end
  end
  mg.write("
\n")
end
-- Print Lua version and available libraries
mg.write("- " .. _VERSION .. " with the following standard libraries\n")
mg.write("
\n")
libs = {"string", "math", "table", "io", "os", "bit32", "utf8", "package", "coroutine", "debug"};
for _,n in ipairs(libs) do
  print_if_available(_G[n], n);
end
mg.write("
\n")
print_if_available(sqlite3, "sqlite3 binding")
print_if_available(lfs, "lua file system")
--recurse(_G)
-- Print mg library
libname = "mg"
print_if_available(_G[libname], libname .. " library")
recurse(_G[libname])
-- Print connect function
print_if_available(connect, "connect function")
mg.write("
\n");
mg.write(" Today is " .. os.date("%A") .. "
\n");
l = mg.request_info.content_length
if l then
  mg.write("Content-Length = "..l..":
\n
\n")
  mg.write(mg.read())
  mg.write("\n\n\n")
end
mg.write("\n");
 if lfs then
  mg.write("Files in " .. lfs.currentdir())
  mg.write("\n
\n")
  for f in lfs.dir(".") do
    local mime = mg.get_mime_type(f)
    mg.write("- " .. f .. " (" .. mime .. ")\n")
    local at = lfs.attributes(f);
    recurse(at)
  end
  mg.write("
\n")
end
mg.write([[
]])