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