-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(trafiic-split): support rules based on json request body #11289
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
feat(trafiic-split): support rules based on json request body #11289
Conversation
please add test cases and docs |
I have added test cases and docs, please let me know if there are anything missing, thank you. 😃 |
apisix/core/ctx.lua
Outdated
"application/json") then | ||
local arg_key = sub_str(key, 15) | ||
local raw_request_body = request.get_body() | ||
local body = cjson.decode(raw_request_body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
local body = cjson.decode(raw_request_body) | |
local body, err = core.json.decode(raw_request_body) |
apisix/core/ctx.lua
Outdated
local raw_request_body = request.get_body() | ||
local body = cjson.decode(raw_request_body) | ||
if body then | ||
val = utils.get_nested_json_value(body, arg_key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use jsonpath?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, just updated code using jsonpath, thank you. 😃
a38ffde
to
5630aa7
Compare
"application/json") then | ||
local arg_key = sub_str(key, 15) | ||
local raw_request_body = request.get_body() | ||
local body, err = json.decode(raw_request_body) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using a cache, as this code may be executed multiple times on hot paths.
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the [email protected] list. Thank you for your contributions. |
This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
Description
After this change, the traffic-split will be able to support rules based on json body in POST request. For example:
If we create a route like this:
In traffic-split we defined "json_body_arg_cat.sounds_like" == "mewo", which means it will match the json body like this:
Motivation:
Currently the traffic-split plugin can create rules based on the default form of the POST request.
However it does not support rules based on application/json in the POST request body.
I think it will be great if it can support the rules based on json body as well.
As I have the need to have rules based on json body too.
Fixes # (issue)
Checklist