Rather than routing a request to a service within your service mesh, you can send back a pre-defined body and HTTP status response to the client. If necessary, you can also specify headers by using the Header Modification feature in the enclosing route.

For more information, see the Gloo Mesh Gateway API docs for route tables.

  1. Create a virtual gateway that opens up port 80 on your ingress gateway.

      kubectl apply -f- <<EOF
    apiVersion: networking.gloo.solo.io/v2
    kind: VirtualGateway
    metadata:
      name: istio-ingressgateway
      namespace: bookinfo
    spec:
      workloads:
        # Matches on 'spec.selector' labels for the ingress gateway service
        - selector:
            labels:
              istio: ingressgateway
            cluster: ${CLUSTER_NAME}
      listeners:
        # The port the ingress gateway listens on for incoming requests to route
        - port:
            number: 80
          http: {}
    EOF
      
  2. Create a direct response route table, and specify the status and optional body that is returned. In the following example, the 510 status and no longer supported message are immediately returned in response to any requests to the /unsupported-app path.

      kubectl apply -n global -f- <<EOF
    apiVersion: networking.gloo.solo.io/v2
    kind: RouteTable
    metadata:
      name: direct-response
      namespace: global
    spec:
      hosts:
        - '*'
      # Selects the virtual gateway you previously created
      virtualGateways:
        - name: istio-ingressgateway
          namespace: bookinfo
          cluster: ${CLUSTER_NAME}
      http:
        - name: unsupported-app-route
          # Prefix matching
          matchers:
          - uri:
              prefix: /unsupported-app
          # Immediately returns this 510 response
          directResponse:
            body: '{"message": "no longer supported"}'
            status: 510
    EOF
      
  3. Get the external address of your ingress gateway.

      export INGRESS_GW_ADDRESS=$(kubectl get svc -n gloo-mesh-gateways istio-ingressgateway -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}")
    echo $INGRESS_GW_ADDRESS
      
  4. Verify that you receive the expected direct response by curling the ingress gateway address and, if applicable, the path. For example, the following command appends /unsupported-app.

      curl http://$INGRESS_GW_ADDRESS/unsupported-app