Function Description

The custom-response plugin supports the configuration of custom responses, including custom HTTP response status codes, HTTP response headers, and HTTP response bodies. It can be used for Mock responses or for providing custom responses based on specific status codes, such as implementing custom responses when triggering the gateway rate-limiting policy.

Running Attributes

Plugin Execution Phase: Authentication Phase

Plugin Execution Priority: 910

Configuration Fields

NameData TypeRequirementsDefault ValueDescription
status_codenumberOptional200Custom HTTP response status code
headersarray of stringOptional-Custom HTTP response headers, keys and values separated by =
bodystringOptional-Custom HTTP response body
enable_on_statusarray of numberOptional-Match original status codes to generate custom responses; if not specified, the original status code is not checked

Configuration Example

Mock Response Scenario

  1. status_code: 200
  2. headers:
  3. - Content-Type=application/json
  4. - Hello=World
  5. body: “{\”hello\”:\”world\”}”

With this configuration, the request will return the following custom response:

  1. HTTP/1.1 200 OK
  2. Content-Type: application/json
  3. Hello: World
  4. Content-Length: 17
  5. {“hello”:”world”}

Custom Response on Rate Limiting

  1. enable_on_status:
  2. - 429
  3. status_code: 302
  4. headers:

When the gateway rate limiting is triggered, it generally returns the 429 status code, and the request will return the following custom response:

  1. HTTP/1.1 302 Found

This achieves the goal of redirecting users who have been rate-limited to another page based on the browser’s 302 redirect mechanism, which could be a static page on a CDN.

If you wish to return other responses normally when rate limiting is triggered, just refer to the Mock response scenario to configure the relevant fields accordingly.