-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
上面的代碼片段會做什麼?