I’m working with the Kong API Gateway (OSS) and trying to modify the response payload. However, I’ve noticed that it’s not possible to add third-party dependencies in the sandbox of the post plugin, which makes it challenging to create a reliable and robust solution for reworking the response payload.
I also attempted to build a Go plugin.
However, I noticed that the kong.response.set_raw_body function is not accessible in the Go PDK, limiting my ability to directly set the modified response body.
Has anyone found a workaround or a recommended approach to reliably modify the response payload in Kong?
I don’t quite understand, what do you mean with “not possible to add third-party dependencies”, but…
You can always clone the code of “response-transformer” plugin from the Kong OSS repository,
modify the function “body_filter”
For simple plugins, it is enough to copy the new plugin to the /usr/local/share/lua/5.1/kong/plugins/ folder.
However, if you need additional Lua packages, you can
install any dependencies with “luarocks install …”
build your package with “luarocks make” and “luarocks pack …”
If you run the above commands in a Dockerfile, then “luarocks” is already provided in the Kong base image.
At least this approach works for our custom plugins.