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 2021/02/09 11:12:41 UTC

[GitHub] [apisix] spacewander commented on a change in pull request #3396: change: global rules should not be executed on the internal api

spacewander commented on a change in pull request #3396:
URL: https://github.com/apache/apisix/pull/3396#discussion_r572797909



##########
File path: conf/config-default.yaml
##########
@@ -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

Review comment:
       Can we add test when global_rule_skip_internal_api is false?

##########
File path: apisix/init.lua
##########
@@ -325,8 +325,29 @@ function _M.http_access_phase()
 
     core.ctx.set_vars_meta(api_ctx)
 
+    local uri = api_ctx.var.uri
+    if local_conf.apisix and local_conf.apisix.delete_uri_tail_slash then
+        if str_byte(uri, #uri) == str_byte("/") then
+            api_ctx.var.uri = str_sub(api_ctx.var.uri, 1, #uri - 1)
+            core.log.info("remove the end of uri '/', current uri: ",
+                          api_ctx.var.uri)
+        end
+    end
+
+    local matched_internal_api = false
+    if router.api.has_route_not_under_apisix() or
+        core.string.has_prefix(uri, "/apisix/")
+    then
+        matched_internal_api = router.api.match(api_ctx)

Review comment:
       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 https://github.com/apache/apisix/blob/c895cdf4ff008c13dec8197e9f0a0407be144517/apisix/api_router.lua#L124




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org