nanamikon opened a new issue #3565:
URL: https://github.com/apache/apisix/issues/3565


   ### Issue description
   Relate to #3528 
   
   I think we can add a feature to customize the body when response exits.   
For example,  different format of json,  even html
    or xml ,   can be use to display the exit message
   
   Refer to apisix/core/response.lua,   resp_exit will be called when response 
exits,  I think it is a global handle for response exiting, 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)
         ';
       }
   ```
   
   Some discussion about kong
   
   1 Kong error response
   https://github.com/Kong/kong/issues/3192
   
   2 Upstream error response
   https://github.com/Kong/kong/issues/972
   
   ### Environment
   
   * apisix version (cmd: `apisix version`):2.2
   * OS (cmd: `uname -a`):ubuntu 16
   * OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): 1.19
   * etcd version, if have (cmd: run `curl 
http://127.0.0.1:9090/v1/server_info` to get the info from server-info 
API):3.4.17
   * apisix-dashboard version, if have:
   


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


Reply via email to