generated from lualoader-dev/lualoader-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
78 lines (75 loc) · 2.26 KB
/
main.lua
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
68
69
70
71
72
73
74
75
76
77
78
-- main.lua
require("enable")
require("disable")
HandlerTable = {
["/hello"] = function (r)
print("hello from lua")
return {
status = 200,
header = {
Test = {"a", "B"}
},
body = "hello http (from lua)"
}
end,
["/bye"] = function (r)
print("bye from lua")
return {
status = 200,
header = {
Test = {"C", "d"}
},
body = "bye http (from lua)"
}
end,
["/test"] = function (r)
print("get test")
local strHeader = "header:\n"
local strForm = "form:\n"
local strPostForm = "postForm:\n"
local strTrailer = "trailer:\n"
local strURLQuery = "urlQuery:\n"
for k, v in pairs(r.header) do
for k2, v2 in pairs(v) do
strHeader = strHeader .. string.format("%s: %d. %s\n", k, k2, v2)
end
end
for k, v in pairs(r.form) do
for k2, v2 in pairs(v) do
strForm = strForm .. string.format("%s: %d. %s\n", k, k2, v2)
end
end
for k, v in pairs(r.postForm) do
for k2, v2 in pairs(v) do
strPostForm = strPostForm .. string.format("%s: %d. %s\n", k, k2, v2)
end
end
for k, v in pairs(r.trailer) do
for k2, v2 in pairs(v) do
strTrailer = strTrailer .. string.format("%s: %d. %s\n", k, k2, v2)
end
end
for k, v in pairs(r.urlQuery) do
for k2, v2 in pairs(v) do
strURLQuery = strURLQuery .. string.format("%s: %d. %s\n", k, k2, v2)
end
end
return {
status = 200,
header = {},
body = string.format("method: %s\nproto: %s\nbody: %s\nhost: %s\nremoteAddr: %s\nrequestURI: %s\n========\n%s\n--------\n%s\n--------\n%s\n--------\n%s\n--------\n%s\n",
r.method,
r.proto,
r.body,
r.host,
r.remoteAddr,
r.requestURI,
strHeader,
strForm,
strPostForm,
strTrailer,
strURLQuery
)
}
end
}