page3.lua 1016 B

12345678910111213141516171819202122
  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. filename = mg.document_root .. "/" .. mg.request_info.query_string
  20. mg.send_file(filename)
  21. end