You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "spacewander (via GitHub)" <gi...@apache.org> on 2023/03/21 02:36:58 UTC

[GitHub] [apisix] spacewander commented on a diff in pull request #9112: feat: support variable when rewrite header in proxy rewrite plugin

spacewander commented on code in PR #9112:
URL: https://github.com/apache/apisix/pull/9112#discussion_r1142838545


##########
apisix/core/utils.lua:
##########
@@ -335,4 +335,45 @@ end
 _M.resolve_var = resolve_var
 
 
+local resolve_var_with_captures
+do
+    local _captures
+    -- escape is not supported very well, like there si a redundant '\' after escape "$1"

Review Comment:
   ```suggestion
       -- escape is not supported very well, like there is a redundant '\' after escape "$1"
   ```



##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -278,15 +284,24 @@ function _M.rewrite(conf, ctx)
 
         local uri, _, err = re_sub(upstream_uri, conf.regex_uri[1],
                                    conf.regex_uri[2], "jo")
-        if uri then
-            upstream_uri = uri
-        else
+        if not uri then
             local msg = "failed to substitute the uri " .. ctx.var.uri ..
                         " (" .. conf.regex_uri[1] .. ") with " ..
                         conf.regex_uri[2] .. " : " .. err
             core.log.error(msg)
             return 500, {message = msg}
         end
+
+        local m, err = re_match(upstream_uri, conf.regex_uri[1], "jo")
+        if not m then
+            if err then
+                core.log.error("match error in proxy-rewrite plugin, please check: ", err)
+                return

Review Comment:
   Do we need to return a 503 for this error?



##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -278,15 +284,24 @@ function _M.rewrite(conf, ctx)
 
         local uri, _, err = re_sub(upstream_uri, conf.regex_uri[1],
                                    conf.regex_uri[2], "jo")
-        if uri then
-            upstream_uri = uri
-        else
+        if not uri then
             local msg = "failed to substitute the uri " .. ctx.var.uri ..
                         " (" .. conf.regex_uri[1] .. ") with " ..
                         conf.regex_uri[2] .. " : " .. err
             core.log.error(msg)
             return 500, {message = msg}
         end
+
+        local m, err = re_match(upstream_uri, conf.regex_uri[1], "jo")
+        if not m then
+            if err then

Review Comment:
   We can merge the two conditions above?



##########
apisix/core/utils.lua:
##########
@@ -335,4 +335,45 @@ end
 _M.resolve_var = resolve_var
 
 
+local resolve_var_with_captures
+do
+    local _captures
+    -- escape is not supported very well, like there si a redundant '\' after escape "$1"
+    local pat = [[ (?<! \\) \$ \{? (\d+) \}? ]]
+
+    local function resolve(m)
+        local v = _captures[tonumber(m[1])]

Review Comment:
   Do we need to support capture group name?



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