This is an automated email from the ASF dual-hosted git repository.

baoyuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a22fc803 fix(request-validation): support Content-Type header with 
charset for urlencoded data (#12406)
2a22fc803 is described below

commit 2a22fc80375d176c2f9f96aab47ce223a43473f6
Author: Baoyuan <baoyuan....@gmail.com>
AuthorDate: Fri Jul 11 15:24:07 2025 +0800

    fix(request-validation): support Content-Type header with charset for 
urlencoded data (#12406)
---
 apisix/plugins/request-validation.lua |  7 ++++++-
 t/plugin/request-validation.t         | 11 +++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/apisix/plugins/request-validation.lua 
b/apisix/plugins/request-validation.lua
index 0e6d36d95..138032f42 100644
--- a/apisix/plugins/request-validation.lua
+++ b/apisix/plugins/request-validation.lua
@@ -88,7 +88,12 @@ function _M.rewrite(conf, ctx)
         end
 
         local body_is_json = true
-        if headers["content-type"] == "application/x-www-form-urlencoded" then
+        if headers["content-type"]
+            and core.string.has_prefix(
+                headers["content-type"]:lower(),
+                "application/x-www-form-urlencoded"
+            )
+        then
             -- use 0 to avoid truncated result and keep the behavior as the
             -- same as other platforms
             req_body, err = ngx.decode_args(body, 0)
diff --git a/t/plugin/request-validation.t b/t/plugin/request-validation.t
index f1272c69e..fcb440729 100644
--- a/t/plugin/request-validation.t
+++ b/t/plugin/request-validation.t
@@ -1783,3 +1783,14 @@ Content-Type: application/x-www-form-urlencoded
 " . "a=b&" x 101 . "required_payload=101-hello"
 --- response_body eval
 qr/101-hello/
+
+
+
+=== TEST 53: test urlencoded post data with charset header
+--- more_headers
+Content-Type: application/x-www-form-urlencoded; charset=utf-8
+--- request eval
+"POST /echo
+" . "a=b&" x 101 . "required_payload=101-hello"
+--- response_body eval
+qr/101-hello/

Reply via email to