Read response from auth_request in openresty nginx.

20 views
Skip to first unread message

Rohit Dk

unread,
Apr 6, 2022, 9:27:13 AMApr 6
to openresty-en
Hello All,

I am using openresty nginx bundle and i add two endpoint i want  that if auth is sussefull but in response my errorfound parameter give "Yes" then it will not redirect to actual  endpoint. i used below code .
location /endpoint1 {
       
        proxy_set_header Host $host;
        header_filter_by_lua_block { ngx.header.content_length = nil }
        body_filter_by_lua_block {
            local body = ngx.arg[1]
           if string.match(body,'"errorfound":"Yes"') then  
                 body = ngx.re.gsub(body, '"errorfound":"Yes"', "myothervar")
             
           
            end
         
    }
     
    }
location /endpoint2/ {
     
        auth_request     /endpoint1;
        auth_request_set $auth_status $upstream_status;

        rewrite ^/auth/(.*) /$1 break;
        proxy_pass http://endpoint2;
 
  }

Junlong li

unread,
Apr 9, 2022, 1:07:17 AMApr 9
to openresty-en
you may use ngx_http_lua_request instead of  auth_request 
Reply all
Reply to author
Forward
0 new messages