This plugin allows you to transform the response sent by the upstream server on the fly before returning it to the client.
The Response Transformer Advanced plugin provides features that aren’t available in the Response Transformer plugin, including:
- When transforming a JSON payload, transformations are applied to nested JSON objects and
arrays. This can be turned enabled and disabled using the
config.dots_in_keys
configuration parameter. See Arrays and nested objects for more information. - Transformations can be restricted to responses with specific status codes using various
config.*.if_status
configuration parameters. - JSON body contents can be restricted to a set of allowed properties with
config.allow.json
. - The entire response body can be replaced using
config.replace.body
. - Arbitrary transformation functions written in Lua can be applied.
- The plugin will decompress and recompress Gzip-compressed payloads
when the
Content-Encoding
header isgzip
.
Notes:
- Transformations on the response body can cause changes in performance. To parse and modify a JSON body, the plugin needs to retain it in memory, which might cause pressure on the worker’s Lua VM when dealing with large bodies (several MB). Because of Nginx’s internals, the
Content-Length
header will not be set when transforming a response body.- If the value contains a
,
then the comma separated format for lists cannot be used. Array notation must be used instead.