bzp2010 commented on code in PR #12435:
URL: https://github.com/apache/apisix/pull/12435#discussion_r2222814336


##########
apisix/plugins/forward-auth.lua:
##########
@@ -124,13 +125,19 @@ function _M.access(conf, ctx)
             if type(value) == "number" then
                 value = tostring(value)
             end
-            local resolve_value, err = core.utils.resolve_var(value, ctx.var)
-            if not err then
-                auth_headers[header] = resolve_value
-            end
-            if err then
-                core.log.error("failed to resolve variable in extra header '",
-                                header, "': ",value,": ",err)
+            if core.string.has_prefix(value, "$") then
+                -- If the value starts with a dollar sign, treat it as a 
variable
+                -- and resolve it from the context.
+                local sub_str_len = #value - 1  -- Exclude the dollar sign
+                if sub_str_len > 0 then
+                    local trimmed_value = sub_str(value, 2)  -- Remove the 
dollar sign
+                    local resolve_value = ctx.var[trimmed_value]
+                    if resolve_value then
+                        auth_headers[header] = resolve_value
+                    end
+                end
+            else
+                auth_headers[header] = value

Review Comment:
   I disagree with this.
   
   The `core.utils.resolve_var` not only resolves `$var_1` but also templates 
of strings with mixed formatting like `fixed${var_1}fixed${var_2}`, where `$` 
does not need to be an initial letter.
   Your snippet asserts this, which subverts the basis of any previous 
implementation of variable resolution we've had.



-- 
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-unsubscr...@apisix.apache.org

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

Reply via email to