Proposal
Background
Currently, advanced matching only uses URL query data when matching on request content, and does not support advanced matching with fields in POST form as conditions.
Objectives
Support for POST form as matching conditions by adding new matching key.
Solutions
Determine the added matching key prefix
I think we can add a new post_arg_ prefix as a POST form data prefix, this is similar to the arg_ used in the query parameter currently provided by openresty.
Modify the mt metatable in ctx.lua and add a new key processor
The main purpose of the current modification is to handle POST form submissions with Content-Type x-www-form-urlencoded.
Use ngx.req.read_body() and fetch data from ngx.req.get_post_args() according to read requirements in the metatable to achieve complete on-demand inert loading with the help of the metatable feature. The currently used lua-resty-expr can automatically get the target value and compare it with the meta table based on the expression.
current arg_:
|
elseif core_str.has_prefix(key, "arg_") then |
|
local arg_key = sub_str(key, 5) |
|
local args = request.get_uri_args()[arg_key] |
|
if args then |
|
if type(args) == "table" then |
|
val = args[1] |
|
else |
|
val = args |
|
end |
|
end |
demo:
if core_str.has_prefix(key,"post_arg_") then
ngx.req.read_body()
local args, err = ngx.req.get_post_args()
loacl post_arg_key = sub_str(key, 10)
val = args[post_arg_key]
Pre-fetching modifications
apisix/core/ctx.lua: Add new key processor
t/*: Add test case
- Add documents for new function
- Optional: Add support for its configuration to the Dashboard
Other
What are your ideas?
Proposal
Background
Currently, advanced matching only uses URL query data when matching on request content, and does not support advanced matching with fields in POST form as conditions.
Objectives
Support for POST form as matching conditions by adding new matching key.
Solutions
Determine the added matching key prefix
I think we can add a new
post_arg_prefix as a POST form data prefix, this is similar to thearg_used in the query parameter currently provided by openresty.Modify the mt metatable in
ctx.luaand add a new key processorThe main purpose of the current modification is to handle POST form submissions with
Content-Type x-www-form-urlencoded.Use
ngx.req.read_body()and fetch data fromngx.req.get_post_args()according to read requirements in the metatable to achieve complete on-demand inert loading with the help of the metatable feature. The currently usedlua-resty-exprcan automatically get the target value and compare it with the meta table based on the expression.current
arg_:apisix/apisix/core/ctx.lua
Lines 167 to 176 in 042ce5c
demo:
Pre-fetching modifications
apisix/core/ctx.lua: Add new key processort/*: Add test caseOther
What are your ideas?