Skip to content

Proposal: support advanced matching based on POST form #5399

Description

@bzp2010

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_:

apisix/apisix/core/ctx.lua

Lines 167 to 176 in 042ce5c

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

  1. apisix/core/ctx.lua: Add new key processor
  2. t/*: Add test case
  3. Add documents for new function
  4. Optional: Add support for its configuration to the Dashboard

Other

What are your ideas?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions