[Question] How to modify the response body after kong.response.exit(in access phase)? #13225
-
Hi guys, I found that I can not modify the response body in a post-function plugin if kong.response.exit in access phase. What I want is to modify the response body when key-auth failed. Do you have any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The API is designed so that the response cannot be overwritten. A possible workaround is to proxy the same route twice (an extra route to the proxy port) and change the response in the downstream proxy. |
Beta Was this translation helpful? Give feedback.
-
SOLVED! I write a custom plugin to modify the response body. Here is the key steps:
Here is an example: function _M:header_filter(conf)
kong.response.clear_header("Content-Length")
end
function _M:body_filter(conf)
-- replace the body here
local new_body = ...
return kong.response.set_raw_body(new_body)
end
|
Beta Was this translation helpful? Give feedback.
SOLVED! I write a custom plugin to modify the response body. Here is the key steps:
Content-Length
header inheader_filter
phasebody_filter
phaseHere is an example: