-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools): request-aware-table pr feedback
* refactor * only use static log level to turn concurrency checks on or off * use single metatable, keep data and request_id in the instance * use table.new -style initialization * reintroduce :clear() method Co-authored-by: Datong Sun <[email protected]>
- Loading branch information
Showing
5 changed files
with
126 additions
and
150 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
changelog/unreleased/kong/11017.yaml → ...g/unreleased/kong/request-aware-table.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
message: Add a request-aware table able to detect accesses from different requests. | ||
type: feature | ||
scope: Core | ||
prs: | ||
- 11017 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 17 additions & 24 deletions
41
spec/fixtures/custom_plugins/kong/plugins/request-aware-table/handler.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,39 @@ | ||
local RAT = require "kong.tools.request_aware_table" | ||
|
||
local get_phase = ngx.get_phase | ||
local kong = kong | ||
|
||
local tab | ||
|
||
local _M = { | ||
PRIORITY = 1001, | ||
VERSION = "1.0", | ||
} | ||
|
||
local tab = RAT.new({}) | ||
|
||
local function access_tables() | ||
local query = kong.request.get_query() | ||
|
||
if query.clear == "true" and get_phase() == "access" then | ||
-- clear before access | ||
tab.clear() | ||
end | ||
|
||
local function access_table() | ||
-- write access | ||
tab.foo = "bar" | ||
tab.bar = "baz" | ||
-- read/write access | ||
tab.baz = tab.foo .. tab.bar | ||
|
||
if query.clear == "true" and get_phase() == "body_filter" then | ||
-- clear after access | ||
tab.clear() | ||
end | ||
end | ||
|
||
|
||
function _M:access(conf) | ||
access_tables() | ||
end | ||
local query = kong.request.get_query() | ||
if query.new_tab == "true" then | ||
-- new table | ||
tab = RAT.new() | ||
end | ||
|
||
function _M:header_filter(conf) | ||
access_tables() | ||
end | ||
-- access multiple times during same request | ||
access_table() | ||
access_table() | ||
access_table() | ||
|
||
function _M:body_filter(conf) | ||
access_tables() | ||
if query.clear == "true" then | ||
-- clear table | ||
tab:clear() | ||
end | ||
end | ||
|
||
|
||
return _M |