Skip to content

Commit

Permalink
Fix : UserAgent filter raise exception when user agent is null
Browse files Browse the repository at this point in the history
  • Loading branch information
alexazhou committed Feb 17, 2016
1 parent ed44a9c commit 8381b8f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions VeryNginx/lua_script/module/filter.lua
Expand Up @@ -26,17 +26,17 @@ end

function _M.filter_ip()
if VeryNginxConfig.configs["filter_ip_enable"] ~= true then
return false;
return true
end

local remote_addr = ngx.var.remote_addr
for i, v in ipairs( VeryNginxConfig.configs['filter_ip_rule'] ) do
if v[1] == remote_addr then
return true
return false
end
end

return false
return true
end

function _M.filter_useragent()
Expand All @@ -47,6 +47,10 @@ function _M.filter_useragent()
local find = ngx.re.find
local http_user_agent = ngx.var.http_user_agent

if http_user_agent == nil then
return true
end

for i, v in ipairs( VeryNginxConfig.configs["filter_useragent_rule"] ) do
if find( http_user_agent, v[1], "is" ) then
return false
Expand Down Expand Up @@ -108,7 +112,7 @@ function _M.filter()
return
end

if _M.filter_ip() == true then
if _M.filter_ip() ~= true then
ngx.exit( ngx.HTTP_SERVICE_UNAVAILABLE )
end

Expand Down

0 comments on commit 8381b8f

Please sign in to comment.