Kong/kong-python-pdk

Support for manipulating response body in Python PDK

Opened this issue · 5 comments

Hello,

I'm developing a Kong plugin using the Python PDK. One of the requirements of my plugin is to manipulate the response body, similar to how it's done in the Lua PDK with ngx.arg[1] during the body_filter phase. (or response.set_raw_body)

However, I've noticed that the Python PDK doesn't seem to support the body_filter phase or provide a direct way to interact with the response body in chunks

Hi @Hicham-Chahboune , response.set_raw_body is not supported in external plugins, however you can consider using response.exit instead.

Thank you for your response. The issue with "response.exit" is that it interrupts the execution process of plugins. When a plugin calls "response.exit," it prevents the process from passing to other plugins

@Hicham-Chahboune That is correct. Unfortunately that's the limitation we have.

And with Lua, is it possible to change the content of the body? I tried to assign a new value to ngx.arg[1], but it doesn't work. When I manipulate the content without changing it, it works (for example, using ngx.arg[1] = string.upper(body) works). However, when I try to assign a new variable like newbody, it does not work (for example, using ngx.arg[1] = newbody)

yes in lua it's supported, the more detailed documentation is at openresty side (ref: https://github.com/openresty/lua-nginx-module#body_filter_by_lua_block)