monkeyDluffy6017 commented on code in PR #9841:
URL: https://github.com/apache/apisix/pull/9841#discussion_r1267079460
##########
apisix/plugins/ua-restriction.lua:
##########
@@ -81,27 +70,53 @@ local _M = {
schema = schema,
}
-local function match_user_agent(user_agent, conf)
- user_agent = str_strip(user_agent)
- if conf.allowlist then
- for _, rule in ipairs(conf.allowlist) do
+local function check_with_allow_list(user_agents, allowlist)
+ local check = function (user_agent)
+ user_agent = str_strip(user_agent)
+
+ for _, rule in ipairs(allowlist) do
if re_find(user_agent, rule, "jo") then
return true
end
end
return false
end
- if conf.denylist then
- for _, rule in ipairs(conf.denylist) do
+ if type(user_agents) == "table" then
+ for _, v in ipairs(allowlist) do
+ if lrucache_allow(v, allowlist, check, v) then
+ return true
+ end
+ end
+ return false
+ else
+ return lrucache_allow(user_agents, allowlist, check, user_agents)
+ end
+end
+
+
+local function check_with_deny_list(user_agents, denylist)
+ local check = function (user_agent)
+ user_agent = str_strip(user_agent)
+
+ for _, rule in ipairs(denylist) do
if re_find(user_agent, rule, "jo") then
- return false
+ return false
end
end
return true
end
- return true
+ if type(user_agents) == "table" then
+ for _, v in ipairs(denylist) do
Review Comment:
```suggestion
for _, v in ipairs(user_agents) do
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]