Local reply modification
Features:
Example of a LocalReplyConfig
In above example, if the status_code is 400, it will be rewritten to 401, the response body will be rewritten to as “not allowed”.
Local reply format modification
The response body content type can be customized. If not specified, the content type is plain/text. There are two body_format
fields; one is the field in the LocalReplyConfig message and the other field in the mapper
. The latter is only used when its mapper is matched. The former is used if there is no any matched mappers, or the matched mapper doesn’t have the body_format
specified.
Optionally, content-type can be modified further via content_type field. If not specified, default content-type is text/plain
for and application/json
for json_format.
Example of a LocalReplyConfig with body_format
field.
mappers:
- filter:
status_code_filter:
comparison:
value:
default_value: 400
runtime_key: key_b
status_code: 401
body_format_override:
text_format: "<h1>%LOCAL_REPLY_BODY% %REQ(:path)%</h1>"
content_type: "text/html; charset=UTF-8"
- filter:
comparison:
op: EQ
default_value: 500
runtime_key: key_b
status_code: 501
body_format:
text_format: "%LOCAL_REPLY_BODY% %RESPONSE_CODE%"
In above example, there is a body_format_override
inside the first mapper
with a filter matching status_code == 400
. It generates the response body in plain text format by concatenating %LOCAL_REPLY_BODY% with the :path
request header. It is only used when the first mapper is matched. There is a body_format
at the bottom of the config and at the same level as field mappers
. It is used when non of the mappers is matched or the matched mapper doesn’t have its own specified.