-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
change: global rules should not be executed on the internal api #3396
Conversation
end | ||
end | ||
|
||
if router.api.has_route_not_under_apisix() or |
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.
Maybe we can add a configuration in the config.yaml
for it?
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.
@spacewander do you mean a switch for it ?
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
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.
@spacewander
I thought about it again. There shouldn't have a switch here. If skip the if
branch and continue execution, a 404 will occur because the route does not exist.
And I think if need to configure the plugin for the internal api, it is more appropriate to configure a route and then configure the plugin instead of using the global rule.
What do you think ? Looking forward to your opinion. Thanks.
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.
Better to provide a switch to execute the global rule before matching internal API or don't execute the global rule. It is not skipped the internal API matched.
And I think if need to configure the plugin for the internal api, it is more appropriate to configure a route and then configure the plugin instead of using the global rule.
We can't configure a plugin for internal API, this is the real problem.
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.
@spacewander Thanks for for the explanation. I know that.., emm, will update later.
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.
OK. We can wait for it.
We need a test case for it. |
we have test case for it, : ) |
end | ||
end | ||
|
||
if router.api.has_route_not_under_apisix() or |
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.
OK. We can wait for it.
apisix/init.lua
Outdated
if router.api.has_route_not_under_apisix() or | ||
core.string.has_prefix(uri, "/apisix/") | ||
then | ||
matched_internal_api = router.api.match(api_ctx) |
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.
The internal API will call exit
inside so there is not change to execute the global rule.
Maybe we can refactor and exact the global rule code, then run it before
Line 124 in c895cdf
code, body = route.handler(api_ctx) |
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.
got it, thanks!
@@ -89,6 +89,8 @@ apisix: | |||
role: viewer | |||
|
|||
delete_uri_tail_slash: false # delete the '/' at the end of the URI | |||
global_rule_skip_internal_api: true # does not run global rule in internal apis |
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 add test when global_rule_skip_internal_api is false?
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.
We need to add test when global_rule_skip_internal_api is false.
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.
We need to add test when global_rule_skip_internal_api is false.
sure, test failed now, submit it after solving it.
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.
@spacewander teat case added. please help review when you have time, thanks.
What this PR does / why we need it:
global rules should not be executed on the internal api, currently it will run
access
andrewrite
of plugins in global rule, so we need to change it.Pre-submission checklist: