monkeyDluffy6017 commented on code in PR #10496:
URL: https://github.com/apache/apisix/pull/10496#discussion_r1401558846
##########
t/plugin/body-transformer.t:
##########
@@ -894,3 +894,178 @@ location /demo {
assert(core.json.stably_encode(data1) ==
core.json.stably_encode(data2))
}
}
+
+
+
+=== TEST 13: test x-www-form-urlencoded to JSON
+--- config
+ location /demo {
+ content_by_lua_block {
+ local core = require("apisix.core")
+ local body = core.request.get_body()
+ local data = core.json.decode(body)
+ assert(data.foo == "hello world" and data.bar == 30)
+ }
+ }
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin")
+ local core = require("apisix.core")
+ local req_template = [[{"foo":"{{name .. "
world"}}","bar":{{age+10}}}]]
+ local code, body = t.test('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ string.format([[{
+ "uri": "/foobar",
+ "plugins": {
+ "proxy-rewrite": {
+ "uri": "/demo"
+ },
+ "body-transformer": {
+ "request": {
+ "template": "%s"
+ }
+ }
+ },
+ "upstream": {
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:%d": 1
+ }
+ }
+ }]], req_template:gsub('"', '\\"'), ngx.var.server_port)
+ )
+
+ if code >= 300 then
+ ngx.status = code
+ return
+ end
+ ngx.sleep(0.5)
+
+ local core = require("apisix.core")
+ local http = require("resty.http")
+ local uri = "http://127.0.0.1:" .. ngx.var.server_port .. "/foobar"
+ local data = {name = "hello", age = 20}
+ local body = ngx.encode_args(data)
+ local opt = {method = "POST", body = body, headers =
{["Content-Type"] = "application/x-www-form-urlencoded"}}
Review Comment:
The body is `ngx.encode_args` above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]