CustomResponse

microgateway.airlock.com/v1alpha1


CustomResponse defines a custom response.
The response may be defined for multiple Content-Types, in which case the actual response is selected based on the request’s Accept header.

apiVersion: microgateway.airlock.com/v1alpha1
kind: CustomResponse
metadata:
  name: custom-response-example
spec:
  # replace status code with 400 when this custom response is served
  statusCode: 400

  # provide error responses for JSON, HTML and XML
  content:
    - contentType: application/json
      headers:
        # Set a header with a dynamic value using an Envoy command operator
        - name: X-Request-Id
          value: "%STREAM_ID%"
        # Add a static header
        - name: X-Some-Header
          value: "some-value"
      body:
        value: |-
          {
            "error": "something went wrong"
          }
    - contentType: text/html
      body:
        # Can also inject dynamic values into the body via Envoy command operators.
        value: |-
          <!DOCTYPE html>
          <html lang="en">
          <head>
          <meta charset="utf-8">
          <title>Error</title>
          <style>
            body {
              font-family: Arial, Helvetica, sans-serif;
              background-color: #222222;
            }
            h1 {
              color: #aaaaaa;
            }
          </style>
          </head>
          <body>
          <h1>Something went wrong!</h1>
          <p>Request ID: %STREAM_ID%</p>
          </body>
          </html>
    - contentType: application/xml
      body:
        # Provide body via configmap
        valueFrom:
          configMapKeyRef:
            name: custom-response-example
            key: response.xml
apiVersion: microgateway.airlock.com/v1alpha1
kind: CustomResponse
metadata:
  name: custom-response-redirect-404-example
spec:
  statusCode: 302
  content:
    - contentType: none/none
      headers:
        - name: Location
          value: "https://company.com/error/404.html?request_id=%STREAM_ID%"

CustomResponse

Field Description Type Required Default Allowed Values
metadata defines the resource’s metadata ObjectMeta yes
spec defines the desired CustomResponse. object yes

CustomResponse.spec

Field Description Type Required Default Allowed Values
content specifies the custom response content with different content types.
If multiple content types are specified, the content type which best matches the request’s Accept header is served. The Accept header is interpreted as laid out in RFC-9110, Section 12.5.1, with the caveat that all parameters except the weight q are ignored.

The best match with the Accept header is determined as follows:
  1. The content type with the highest weighted match (q parameter) wins.
  2. In the case of equal weights, the more specific match wins.
  3. If the match specificity is the same, the content type which comes earlier in this list wins.
For example, for a request with Accept: application/json; q=0.8, text/*; q=1, text/plain; q=1:
  • Given a content list with content types text/html and application/json, text/html would be served because it matches an entry with higher weight.
  • Given a content list with content types text/html and text/plain, text/plain would be served because it matches a more specific entry with equal weight.
  • Given a content list with application/xml and image/jpg, application/xml would be served because it comes earlier in the list while neither of them matches any part of the Accept header.
object[] yes
statusCode overrides the HTTP status code of the response.
If not specified, the original upstream or local response’s status code is preserved.
int32 no [100, 599]

CustomResponse.spec.content[]

Field Description Type Required Default Allowed Values
body defines the response body.
If not specified, the response is sent without a body and without a Content-Type header.
object no value{}, valueFrom{}
contentType defines the content type of the response.
If a body is specified, this value is used to populate the Content-Type header.
string yes
headers to add to the response.
Note: If the custom response replaces a local response, the original local response’s headers are also included. If this list specifies a header with the same name as an existing header, the existing header’s value is overwritten.
Note: If the custom response replaces an upstream (backend) response, the upstream response’s headers are not automatically included.
object[] no

CustomResponse.spec.content[].body

Field Description Type Required Default Allowed Values
value defines the response body inline as a string.
Note: Dynamic values can be injected into the body using Envoy command operators, e.g., %STREAM_ID%. Percentage signs not part of command operators must be escaped using %%.
string no
valueFrom specifies the source from which to load the response body. object no

CustomResponse.spec.content[].body.valueFrom

Field Description Type Required Default Allowed Values
configMapKeyRef specifies to load the body from a ConfigMap key.
Note: Dynamic values can be injected into the body using Envoy command operators, e.g., %STREAM_ID%. Percentage signs not part of command operators must be escaped using %%.
object yes

CustomResponse.spec.content[].body.valueFrom.configMapKeyRef

Field Description Type Required Default Allowed Values
key to load from the config map. string yes
name of the resource string yes

CustomResponse.spec.content[].headers[]

Field Description Type Required Default Allowed Values
name defines the name of the header. string yes
value defines the value of the header.
Note: This field supports dynamic values via Envoy command operators, e.g., value: "%STREAM_ID%". Percentage signs not part of command operators must be escaped using %%.
string yes