You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/02/08 07:43:50 UTC

[GitHub] [apisix] nanamikon edited a comment on issue #3528: request help: Why ip-restriction return json instead of default 403 error page

nanamikon edited a comment on issue #3528:
URL: https://github.com/apache/apisix/issues/3528#issuecomment-774942415


   Refer to apisix/core/response.lua,   resp_exit will be called when response exit,  I think it is a global handle for response exit, we can't use plugin extension here。  What about redirecting to a new uri to do the actual work ?
   
   Add method 
   ```
   function _M.register_exit_handle_uri(uri){
          handle_uri = uri
   }
   ```
   
   Modify apisix/core/response.lua
   Add exec to redirect to error handle
   ```
       if handle_uri then
           ngx.exec(handle_uri, {code=xxx, body=yyy});
       else
           if idx > 0 then
             ngx_print(concat_tab(t, "", 1, idx))
           end
       
           if code then
               return ngx_exit(code)
           end   
       end
   
   ```
   
   
   Add new config to change this behavior
   ```
   apisix:
         exit_handle_uri:"/error_handle"
        
   ```
   
   New uri for error handle,added by http_server_configuration_snippet 
   ```
       location = /error_handle {
         content_by_lua '
           local args = ngx.req.get_uri_args()
           ngx.print(args.body)
           return ngx.exit(args.code)
         ';
       }
   ```
   
   


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

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