Direct response
Directly respond to incoming requests without routing the requests to services in your service mesh.
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 (Gloo Platform APIs) API docs for route tables.
Create a direct response route table, and specify the status and optional body that is returned. In the following example, the
510status andno longer supportedmessage are immediately returned in response to any requests to the/unsupported-apppath.kubectl apply --context $REMOTE_CONTEXT1 -n global -f- <<EOF apiVersion: networking.gloo.solo.io/v2 kind: RouteTable metadata: name: direct-response namespace: global spec: # Applies to any services within the mesh hosts: - '*' 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 EOFVerify that you receive the expected direct response by sending a request from one service to another on the correct path in your service mesh. For example, log in to an app in your mesh and send a request to
http://myapp:9080/unsupported-app. Or, you can create a temporary curl pod within your mesh.- Create the curl pod.
kubectl run -it -n bookinfo --context $REMOTE_CONTEXT1 curl \ --image=curlimages/curl:7.73.0 --rm -- sh - Send a request to an app in your mesh on the
/unsupported-apppath.curl http://myapp:9080/unsupported-app -v - Exit the temporary pod. The pod deletes itself.
exit
- Create the curl pod.