-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathutils.lua
More file actions
53 lines (43 loc) · 1.17 KB
/
utils.lua
File metadata and controls
53 lines (43 loc) · 1.17 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
local _M = {}
local analysis = ngx.shared.analysis
local route_table = ngx.shared.routetable
function _M.split(str, sSeparator, nMax, bRegexp)
assert(sSeparator ~= '')
assert(nMax == nil or nMax >= 1)
local aRecord = {}
if str:len() > 0 then
local bPlain = not bRegexp
nMax = nMax or -1
local nField=1 nStart=1
local nFirst,nLast = str:find(sSeparator, nStart, bPlain)
while nFirst and nMax ~= 0 do
aRecord[nField] = str:sub(nStart, nFirst-1)
nField = nField+1
nStart = nLast+1
nFirst,nLast = str:find(sSeparator, nStart, bPlain)
nMax = nMax-1
end
aRecord[nField] = str:sub(nStart)
end
return aRecord
end
function _M.read_data()
ngx.req.read_body()
local data = cjson.decode(ngx.req.get_body_data())
if not data then
ngx.exit(ngx.HTTP_BAD_REQUEST)
end
return data
end
function _M.get_from_route_table(key)
local value = route_table:get(key)
return value
end
function _M.check_if_analysis(host)
local value = analysis:get(host)
if not value then
return false
end
return true
end
return _M