Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: post_arg match fails because content-type contains charset #10372

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apisix/core/ctx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ do

elseif core_str.has_prefix(key, "post_arg_") then
-- only match default post form
if request.header(nil, "Content-Type") == "application/x-www-form-urlencoded" then
local content_type = request.header(nil, "Content-Type")
if content_type ~= nil and core_str.has_prefix(content_type,
"application/x-www-form-urlencoded") then
local arg_key = sub_str(key, 10)
local args = request.get_post_args()[arg_key]
if args then
Expand Down
25 changes: 19 additions & 6 deletions t/core/ctx2.t
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,20 @@ find ctx.req_post_args.test: true



=== TEST 13: missed (post_arg_test is missing)
=== TEST 13: hit with charset
--- request
POST /hello
test=test
--- more_headers
Content-Type: application/x-www-form-urlencoded;charset=utf-8
--- response_body
hello world
--- error_log
find ctx.req_post_args.test: true



=== TEST 14: missed (post_arg_test is missing)
--- request
POST /hello
--- more_headers
Expand All @@ -303,7 +316,7 @@ Content-Type: application/x-www-form-urlencoded



=== TEST 14: missed (post_arg_test is mismatch)
=== TEST 15: missed (post_arg_test is mismatch)
--- request
POST /hello
test=tesy
Expand All @@ -315,7 +328,7 @@ Content-Type: application/x-www-form-urlencoded



=== TEST 15: register custom variable
=== TEST 16: register custom variable
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -351,7 +364,7 @@ Content-Type: application/x-www-form-urlencoded



=== TEST 16: hit
=== TEST 17: hit
--- config
location /t {
content_by_lua_block {
Expand All @@ -375,7 +388,7 @@ find ctx.var.a6_labels_zone: Singapore



=== TEST 17: register custom variable with no cacheable
=== TEST 18: register custom variable with no cacheable
--- config
location /t {
content_by_lua_block {
Expand Down Expand Up @@ -412,7 +425,7 @@ find ctx.var.a6_labels_zone: Singapore



=== TEST 18: hit
=== TEST 19: hit
--- config
location /t {
content_by_lua_block {
Expand Down
75 changes: 75 additions & 0 deletions t/plugin/traffic-split5.t
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,78 @@ GET /server_port?name=jack
--- error_log eval
qr/event timer add: \d+: 12345000:\d+/
--- error_code: 502



=== TEST 9: set upstream for post_arg_id test case
--- config
location /t {
content_by_lua_block {
local json = require("toolkit.json")
local t = require("lib.test_admin").test
local data = {
uri = "/hello",
plugins = {
["traffic-split"] = {
rules = {
{
match = { {
vars = { { "post_arg_id", "==", "1" } }
} },
weighted_upstreams = {
{
upstream = {
name = "upstream_A",
type = "roundrobin",
nodes = {
["127.0.0.1:1970"] = 1
}
},
weight = 1
}
}
}
}
}
},
upstream = {
type = "roundrobin",
nodes = {
["127.0.0.1:1974"] = 1
}
}
}
local code, body = t('/apisix/admin/routes/1',
ngx.HTTP_PUT,
json.encode(data)
)
if code >= 300 then
ngx.status = code
end
ngx.say(body)
}
}
--- response_body
passed



=== TEST 10: post_arg_id = 1 without content-type charset
--- request
POST /hello
id=1
--- more_headers
Content-Type: application/x-www-form-urlencoded
--- response_body
1970



=== TEST 11: post_arg_id = 1 with content-type charset
--- request
POST /hello
id=1
--- more_headers
Content-Type: application/x-www-form-urlencoded;charset=UTF-8
--- response_body
1970
Loading