You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/03/17 06:29:17 UTC
[GitHub] [apisix] saiyoofan opened a new issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
saiyoofan opened a new issue #6643:
URL: https://github.com/apache/apisix/issues/6643
### Description
modify ctx.lua to support content-type application/x-www-form-urlencoded;charset=utf-8 to match route
like this:
```
253 elseif core_str.has_prefix(key, "post_arg_") then
254 -- only match default post form
255 local con_t = request.header(nil, "Content-Type")
256 local con_t_s = sub_str(con_t, 1, 33)
257 if con_t_s == "application/x-www-form-urlencoded" then
258 local arg_key = sub_str(key, 10)
259 local args = request.get_post_args()[arg_key]
260 if args then
261 if type(args) == "table" then
262 val = args[1]
263 else
264 val = args
265 end
266 end
267 end
```
get some errors:
```
[error] 51#51: *10048 lua entry thread aborted: runtime error: /usr/local/apisix/apisix/core/ctx.lua:256: bad argument #1 to 'sub_str' (string expected, got nil)
stack traceback:
coroutine 0:
[C]: in function 'sub_str'
/usr/local/apisix/apisix/core/ctx.lua:256: in function '__index'
/usr/local/apisix//deps/share/lua/5.1/resty/expr/v1.lua:291: in function 'eval'
/usr/local/apisix/apisix/plugins/traffic-split.lua:253: in function 'phase_func'
/usr/local/apisix/apisix/plugin.lua:720: in function 'run_plugin'
/usr/local/apisix/apisix/init.lua:471: in function 'http_access_phase
```
so ,how can I repair it.
thx.
### Environment
- APISIX version (run `apisix version`):
- Operating system (run `uname -a`):
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
- etcd version, if relevant (run `curl http://127.0.0.1:9090/v1/server_info`):
- APISIX Dashboard version, if relevant:
- Plugin runner version, for issues related to plugin runners:
- LuaRocks version, for installation issues (run `luarocks --version`):
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] saiyoofan closed issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
saiyoofan closed issue #6643:
URL: https://github.com/apache/apisix/issues/6643
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] saiyoofan commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
saiyoofan commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1070375852
![企业微信截图_16474850244965](https://user-images.githubusercontent.com/37398738/158751591-04b37724-63f3-4d59-938a-3478ddeec83f.png)
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] saiyoofan commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
saiyoofan commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1072258386
>
Thanks for your enthusiastic help
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] saiyoofan commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
saiyoofan commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1072231212
```
elseif core_str.has_prefix(key, "post_arg_") then
-- only match default post form
if request.header(nil, "Content-Type") ~= nil then
local con_t = sub_str(request.header(nil, "Content-Type"),1,33)
if con_t == "application/x-www-form-urlencoded" then
local arg_key = sub_str(key, 10)
local args = request.get_post_args()[arg_key]
if args then
if type(args) == "table" then
val = args[1]
else
val = args
end
end
end
end
elseif core_str.has_prefix(key, "body_arg_") then
-- only match default body json
if request.header(nil, "Content-Type") ~= nil then
local con_t = sub_str(request.header(nil, "Content-Type"),1,16)
if con_t == "application/json" then
local body, err = request.get_body()
if not body then
return nil, "failed to read body data, " .. (err or "request body has zero size")
end
local arg_key = sub_str(key, 10)
local res
res, err = json.decode(body)
if not res then
return nil, "failed to read body data, " .. err
end
if not res[arg_key] then
return nil, "failed to read body data, json body[" ..
arg_key .. "] is nil"
end
val = res[arg_key]
end
end
```
The above code seems to work fine.
But I'm not sure if there will be other problems.
If you have better suggestions, I hope to help correct me, thank you
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] saiyoofan closed issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
saiyoofan closed issue #6643:
URL: https://github.com/apache/apisix/issues/6643
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] saiyoofan closed issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
saiyoofan closed issue #6643:
URL: https://github.com/apache/apisix/issues/6643
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1072247010
> But I'm not sure if there will be other problems.
> If you have better suggestions, I hope to help correct me, thank you
I don't have a suggestion.
1. a better way to test the stability of your code is to feed back upstream;
1. but APISIX already supports the feature, so I think we will reject this change;
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] saiyoofan commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
saiyoofan commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1070377551
also get some errors!
```
[error] 53#53: *5332 lua entry thread aborted: runtime error: /usr/local/apisix/apisix/init.lua:361: attempt to index field 'var' (a nil value)
stack traceback:
coroutine 0:
/usr/local/apisix/apisix/init.lua: in function 'http_access_phase
```
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] soulbird commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
soulbird commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1070372880
As the error log, `con_t ` is nil.
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1071958956
Instead of changing the source code, you can use `vars` to do the matching.
ref: https://github.com/apache/apisix/blob/9d450d7fe3169a77727df28696d083809b93977a/t/core/ctx2.t#L246-L291
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] saiyoofan commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
saiyoofan commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1072231212
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tzssangglass commented on issue #6643: help request: when content-type is application/x-www-form-urlencoded;charset=utf-8 can't match route
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #6643:
URL: https://github.com/apache/apisix/issues/6643#issuecomment-1071958956
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org