Custom response
Description
custom-response
plugin implements a function of sending custom responses, including custom HTTP response status codes, HTTP response headers and HTTP response body, which can be used in the scenarios of response mocking and sending a custom response for specific status codes, such as customizing the response for rate-limited requests.
Configuration Fields
Name | Type | Requirement | Default Value | Description |
---|---|---|---|---|
status_code | number | Optional | 200 | Custom HTTP response status code |
headers | array of string | Optional | - | Custom HTTP response header. Key and value shall be separated using = . |
body | string | Optional | - | Custom HTTP response body |
enable_on_status | array of number | Optional | - | The original response status code to match. Generate the custom response only the actual status code matches the configuration. Ignore the status code match if left unconfigured. |
Configuration Samples
Mock Responses
According to the configuration above, all the requests will get the following custom response:
Send a Custom Response when Rate-Limited
When rate-limited, normally gateway will return a status code of 429
. Now, rate-limited requests will get the following custom response:
So based on the 302 redirecting mechanism provided by browsers, this can redirect rate-limited users to other pages, for example, a static page hosted on CDN.
If you’d like to send other responses when rate-limited, please add other fields into the configuration, referring to the Mock Responses scenario.
Only Enabled for Specific Routes or Domains
In the rule sample of _match_route_
, route-a
and route-b
are the route names provided when creating a new gateway route. When the current route names matches the configuration, the rule following shall be applied. In the rule sample of _match_domain_
, *.example.com
and test.com
are the domain names used for request matching. When the current domain name matches the configuration, the rule following shall be applied. All rules shall be checked following the order of items in the _rules_
field, The first matched rule will be applied. All remained will be ignored.