Skip to content

Commit

Permalink
feat(dynamic_hook): support non request-scoped hooks
Browse files Browse the repository at this point in the history
When a disabled and non-request scoped hook was called outside of
a request scope, it was producing an error while trying to index ngx.ctx

This commit adds a check to early return from is_group_enabled when
outside of the request scope

This allows for hooks to still work when used in other contexts where
they can be enabled via the always_enable() function
  • Loading branch information
samugi committed Jun 24, 2024
1 parent 0ad11d5 commit 1c2aef5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions kong/dynamic_hook/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local get_request = require "resty.core.base".get_request

local ngx = ngx
local type = type
local pcall = pcall
Expand Down Expand Up @@ -233,6 +235,10 @@ function _M.is_group_enabled(group_name)
return true
end

if not get_request() then
return false
end

local dynamic_hook = ngx.ctx.dynamic_hook
if not dynamic_hook then
return false
Expand Down

0 comments on commit 1c2aef5

Please sign in to comment.