-1
我使用lua与nginx。要访问我的ES群集,我使用lua代码进行配置。我想知道的代码是如何工作..任何人都可以解释下面的LUA代码是如何工作的?
-- get URL
local uri = ngx.var.uri
-- get method
local method = ngx.req.get_method()
local allowed = false
for path, methods in pairs(restrictions[role]) do
-- path matched rules?
local p = string.match(uri, path)
-- method matched rules?
local m = nil
for _, _method in pairs(methods) do
m = m and m or string.match(method, _method)
end
if p and m then
allowed = true
break
end
end
if not allowed then
return write403Message()
end
让被URL: http://localhost/_GET
,method:GET
,path:/_GET
然后
local p = string.match(uri, path) -->Then p variable has value GET(i.e p=GET)
纠正我,如果我错了吗?
for _, _method in pairs(methods) do
m = m and m or string.match(method, _method)
end
上面的代码片段会做什么?