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
5if not mg.request_info.query_string 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 query string!</body></html>\r\n")
12elseif mg.request_info.query_string:match("/") or mg.request_info.query_string:match("\\") then
13    mg.write("HTTP/1.0 403 Forbidden\r\n")
14    mg.write("Connection: close\r\n")
15    mg.write("Content-Type: text/html; charset=utf-8\r\n")
16    mg.write("\r\n")
17    mg.write("<html><head><title>CivetWeb Lua script test page 3</title></head>\r\n")
18    mg.write("<body>No access!</body></html>\r\n")
19else
20    file = mg.get_var(mg.request_info.query_string, "file");
21    if not file then
22        mg.write("HTTP/1.0 400 Bad Request\r\n")
23        mg.write("Connection: close\r\n")
24        mg.write("Content-Type: text/html; charset=utf-8\r\n")
25        mg.write("\r\n")
26        mg.write("<html>\r\n<head><title>CivetWeb Lua script test page 3</title></head>\r\n")
27        mg.write("<body>\r\nQuery string does not contain a 'file' variable.<br>\r\n")
28        mg.write("Try <a href=\"?file=page3.lua&somevar=something\">?file=page3.lua&somevar=something</a>\r\n")
29        mg.write("</body>\r\n</html>\r\n")
30    else
31        filename = mg.document_root .. "/" .. file
32        mg.send_file(filename)
33    end
34end
35