page3.lua 1.6 KB

12345678910111213141516171819202122232425262728293031323334
  1. -- This test checks if a query string has been given.
  2. -- It sends the file identified by the query string.
  3. -- Do not use it in a real server in this way!
  4. if not mg.request_info.query_string then
  5. mg.write("HTTP/1.0 200 OK\r\n")
  6. mg.write("Connection: close\r\n")
  7. mg.write("Content-Type: text/html; charset=utf-8\r\n")
  8. mg.write("\r\n")
  9. mg.write("<html><head><title>Civetweb Lua script test page 3</title></head>\r\n")
  10. mg.write("<body>No query string!</body></html>\r\n")
  11. elseif mg.request_info.query_string:match("/") or mg.request_info.query_string:match("\\") then
  12. mg.write("HTTP/1.0 403 Forbidden\r\n")
  13. mg.write("Connection: close\r\n")
  14. mg.write("Content-Type: text/html; charset=utf-8\r\n")
  15. mg.write("\r\n")
  16. mg.write("<html><head><title>Civetweb Lua script test page 3</title></head>\r\n")
  17. mg.write("<body>No access!</body></html>\r\n")
  18. else
  19. file = mg.get_var(mg.request_info.query_string, "file");
  20. if not file then
  21. mg.write("HTTP/1.0 400 Bad Request\r\n")
  22. mg.write("Connection: close\r\n")
  23. mg.write("Content-Type: text/html; charset=utf-8\r\n")
  24. mg.write("\r\n")
  25. mg.write("<html>\r\n<head><title>Civetweb Lua script test page 3</title></head>\r\n")
  26. mg.write("<body>\r\nQuery string does not contain a 'file' variable.<br>\r\n")
  27. mg.write("Try <a href=\"?file=page3.lua&somevar=something\">?file=page3.lua&somevar=something</a>\r\n")
  28. mg.write("</body>\r\n</html>\r\n")
  29. else
  30. filename = mg.document_root .. "/" .. file
  31. mg.send_file(filename)
  32. end
  33. end