Kong 2.2.0 introduces a new response phase that according to the changelog allows to manipulate both the response headers and the response body in the same phase.
However, while kong.service.response.get_raw_body() and kong.service.response.get_body() are supported in this phase, there is no kong.response.set_raw_body() nor kong.response.set_body().
How can the response body be manipulated in the response phase?
If you look at Kong’s source for response.lua, you’ll see that they’ve, well, considered the PDK function.
For body_filter plugins historically, you would set the response body by setting ngx.arg[1] to the body bytes you wanted to send, typically when ngx.arg[2] was not nil (body_filter plugin phases being called potentially multiple times). Have you tried doing the same for a response phase plugin?
Yes, I tried. But ngx.arg is only available in the set_by_lua and body_filter_by_lua phases.
The error I received is API disabled in the context of access_by_lua*