-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.lua
More file actions
67 lines (56 loc) · 1.52 KB
/
test.lua
File metadata and controls
67 lines (56 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- FastCGI Test Program
local fcgi = require 'fcgi'
-- Create a local socket, make sure the FastCGI enabled webserver
-- has r/w access to it, might need a chmod call here
local socket = fcgi.openSocket('/var/run/.s.luafcgi', 4)
local request = fcgi.initRequest(socket)
-- Accept requests in a loop
while request:accept() == 0 do
print('Incoming request')
local data = request:parse()
print('request parsed', type(data))
for k, v in pairs(data) do
print('decoded', k .. ':')
if type(v) == 'table' then
-- uploaded files have a __isFile boolean set to true
if v.__isFile == true then
for a, b in pairs(v) do
print(a)
if a ~= 'filedata' then
print(b)
end
end
local f = io.open(v.filename, 'w')
f:write(v.filedata)
f:close()
else
-- not a file, must be a selection multiple
for a, b in pairs(v) do
print(a, b)
end
end
else
print(string.format('%s', v))
end
end
-- Send some HTML to the client
request:putStr('Content-Type: text/html\n')
request:putStr('\n')
request:putStr('<h1>Hello from Lua</h1>\n')
request:putStr([[
<form method="POST" enctype="multipart/form-data" action="/cgi/abc">
<input type="file" name="imagefile" value="">
<input type="text" name="name">
<input type="text" name="id">
<select multiple name="selection">
<option value="a">AAA</option>
<option value="b">BBB</option>
<option value="c">CCC</option>
</select>
<input type="submit" value="OK">
</form>
]])
-- finish this request
request:finish()
end
print('ending')