mikyll commented on issue #12121:
URL: https://github.com/apache/apisix/issues/12121#issuecomment-2775684834

   ## Update
   
   I tried using `ngx.var` instead of `ctx.var` and it seems to be working...
   
   ### Example
   
   (Considering the MRE above) additional route, to be added in 
`conf/apisix.yaml`:
   
   ```yaml
   routes:
     # [...]
     - id: test4
       uri: /test4
       upstream_id: httpbin_internal
       plugins:
         proxy-rewrite:
           uri: /status/200
           headers:
             set:
               status: $status      # <- this
               hostname: $hostname  # <- this
         serverless-pre-function:
           phase: header_filter
           functions:
             - |
               return function(conf, ctx)
                 local core = require("apisix.core")
                 local status, err, n_resolved = 
core.utils.resolve_var("$status", ngx.var)
                 local hostname, err, n_resolved = 
core.utils.resolve_var("$hostname", ngx.var)
                 core.log.warn("status: " .. tostring(status) .. ", hostname: " 
.. tostring(hostname))
                 ngx.header["status"] = status
                 ngx.header["hostname"] = hostname
               end
   ```
   
   Test request:
   
   ```bash
   curl -s -i localhost:9080/test4
   HTTP/1.1 200 OK
   ...
   status: 200
   hostname: 0be5febe953a
   ```


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to