vortegatorres commented on issue #11424:
URL: https://github.com/apache/apisix/issues/11424#issuecomment-2260495288

   > > > @vortegatorres
   > > > `upstream_status` is set at `apisix.http_balancer_phase`, but 
`serverless-pre-function @ rewrite phase returning 401(>=200, for more to see 
below) will interrupt that flow.
   > > > If you want to modify the response from upstream, try serverless-xxx @ 
[header | body]_filter phase.
   > > > ```
   > > > core.response.exit(401) -> ngx.exit(401)
   > > > 
   > > > restydoc -s ngx.exit
   > > > 
   > > > When "status >= 200" (i.e., "ngx.HTTP_OK" and above), it will interrupt
   > > >        the execution of the current request and return status code to 
Nginx.
   > > > ...
   > > > ```
   > > 
   > > 
   > > If I understand correctly, the [header|body]_filter phases modify the 
upstream response. In my case, I use the `serverless-pre-function` plugin to be 
called from the `forward-auth` plugin, and there is no upstream body to modify, 
and your suggestion didn't work. Is there a workaround for setting the 
`upstream_status` in this scenario?
   > 
   > Could you show the route/plugins config more similar with your scenario?
   
   I have a route that is authenticated using the `forward-auth` plugin 
pointing to another route using `serverless-pre-function` plugin:
   ```
   apiVersion: apisix.apache.org/v2
   kind: ApisixRoute
   metadata:
     name: service
     namespace: service
   spec:
     http:
       - name: service
         match:
           paths:
             - "/service"
         backends:
           - serviceName: service
             servicePort: 10001
         plugins:
           - name: auth
             enable: true
             config:
               uri: "http://127.0.0.1:9080/auth";
       - name: schemas
         match:
           paths:
             - "/service"
   ```
   
   ```
   apiVersion: apisix.apache.org/v2
   kind: ApisixRoute
   metadata:
     name: auth
   spec:
     http:
       - name: auth
         match:
           paths:
             - "/auth"
         plugins:
           - name: serverless-pre-function
             enable: true
             config:
               phase: rewrite
               functions:
                 - return function(conf, ctx)
                     local core = require("apisix.core");          
       
                     core.response.exit(401);
   ```


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