page3a.lua 1021 B

123456789101112131415161718192021222324252627282930
  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. file = mg.get_var(mg.request_info.query_string, "file");
  5. if not file then
  6. mg.write("HTTP/1.0 200 OK\r\n")
  7. mg.write("Connection: close\r\n")
  8. mg.write("Content-Type: text/html; charset=utf-8\r\n")
  9. mg.write("\r\n")
  10. mg.write("<html><head><title>CivetWeb Lua script test page 3</title></head>\r\n")
  11. mg.write("<body>No file parameter in query string!</body></html>\r\n")
  12. return
  13. end
  14. if file:match("/") or file:match("\\") then
  15. mg.write("HTTP/1.0 403 Forbidden\r\n")
  16. mg.write("Connection: close\r\n")
  17. mg.write("Content-Type: text/html; charset=utf-8\r\n")
  18. mg.write("\r\n")
  19. mg.write("<html><head><title>CivetWeb Lua script test page 3</title></head>\r\n")
  20. mg.write("<body>No access!</body></html>\r\n")
  21. return
  22. end
  23. filename = mg.document_root .. "/" .. file
  24. mg.send_file(filename)