]>
Commit | Line | Data |
---|---|---|
1 | #!/usr/bin/lua5.1\r | |
2 | \r | |
3 | -- Every CGI script that returns any valid JSON object will work in the test.\r | |
4 | -- In case you do not have not yet used CGI, you may want to use this script which is written in Lua.\r | |
5 | -- You may download an interpreter from http://luabinaries.sourceforge.net/download.html, extract it\r | |
6 | -- to some folder in your search path (the path of the webserver or /usr/bin on Linux), and add the\r | |
7 | -- following lines to your .conf file.\r | |
8 | -- cgi_interpreter c:\somewhere\lua5.1.exe\r | |
9 | -- enable_keep_alive yes\r | |
10 | \r | |
11 | resp = "{";\r | |
12 | \r | |
13 | method = os.getenv("REQUEST_METHOD")\r | |
14 | uri = os.getenv("REQUEST_URI");\r | |
15 | query = os.getenv("QUERY_STRING");\r | |
16 | datalen = os.getenv("CONTENT_LENGTH");\r | |
17 | \r | |
18 | if method then\r | |
19 | resp = resp .. '"method" : "' .. method .. '", ';\r | |
20 | end\r | |
21 | if uri then\r | |
22 | resp = resp .. '"uri" : "' .. uri .. '", ';\r | |
23 | end\r | |
24 | if query then\r | |
25 | resp = resp .. '"query" : "' .. query .. '", ';\r | |
26 | end\r | |
27 | if datalen then\r | |
28 | resp = resp .. '"datalen" : "' .. datalen .. '", ';\r | |
29 | end\r | |
30 | \r | |
31 | resp = resp .. '"time" : "' .. os.date() .. '" ';\r | |
32 | \r | |
33 | resp = resp .. "}";\r | |
34 | \r | |
35 | \r | |
36 | \r | |
37 | \r | |
38 | print "Status: 200 OK"\r | |
39 | print "Connection: close"\r | |
40 | --print "Connection: keep-alive"\r | |
41 | print "Content-Type: text/html; charset=utf-8"\r | |
42 | print "Cache-Control: no-cache"\r | |
43 | --print ("Content-Length: " .. resp:len())\r | |
44 | print ""\r | |
45 | \r | |
46 | print (resp)\r | |
47 | \r | |
48 | \r | |
49 | doLogging = false\r | |
50 | \r | |
51 | if (doLogging) then\r | |
52 | -- Store the POST data to a file\r | |
53 | if (method == "POST") then\r | |
54 | myFile = io.open("data" .. query:sub(4) .. ".txt", "wb");\r | |
55 | myFile:write(resp)\r | |
56 | myFile:write("\r\n\r\n") \r | |
57 | if datalen then\r | |
58 | datalen = tonumber(datalen)\r | |
59 | myFile:write("<<< " .. datalen .. " bytes of data >>>\r\n")\r | |
60 | \r | |
61 | data = io.stdin:read(datalen)\r | |
62 | myFile:write(data)\r | |
63 | \r | |
64 | myFile:write("\r\n<<< end >>>\r\n")\r | |
65 | else\r | |
66 | myFile:write("<<< no data >>>\r\n")\r | |
67 | end \r | |
68 | myFile:close()\r | |
69 | end\r | |
70 | end\r | |
71 | \r | |
72 | \r | |
73 | \r |