Related Documentation
Made by
Kong Inc.
Supported Gateway Topologies
hybrid db-less traditional
Supported Konnect Deployments
hybrid cloud-gateways serverless
Compatible Protocols
grpc grpcs http https

Transform and customize Kong Gateway response exit messages using Lua functions. The plugin’s capabilities range from changing messages, status codes, and headers, to completely transforming the structure of Kong Gateway responses.

untrusted_lua must be set to either on or sandbox in your kong.conf file for this plugin to work. The default value is sandbox, which means that Lua functions are allowed, but will be executed in a sandbox which has limited access to the Kong Gateway global environment.

Handling unmatched 400 and 404 responses

You can configure the Exit Transformer plugin to handle 400 and 404 responses by enabling the following parameters:

  • handle_unknown: This parameter allows the plugin to handle 404 responses. It must be used on a globally configured instance of the plugin running in the default Workspace.
  • handle_unexpected: This parameter allows the plugin to handle 400 responses. It can be enabled on any plugin scope.

Function syntax

The Exit Transformer plugin expects a configuration function to be Lua code that returns a function accepting three arguments: status, body, and headers. For example:

return function(status, body, headers)
 return status, body, headers
end

Any Kong Gateway exit call exposed on the proxy side gets reduced through these functions.

Caution: kong.response.exit() requires a status argument only. body and headers may be nil. If you manipulate the body and headers, first check that they exist and instantiate them if they don’t exist.

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!