All Products
Search
Document Center

Alibaba Cloud Service Mesh:Direct response

Last Updated:Dec 01, 2025

For a matched request, a service mesh proxy can directly return an HTTP response to the client according to the configured HTTP rule, instead of forwarding the request to the destination service. This topic describes how to configure a direct response.

Prerequisites

The preparations are completed, and the HTTPBin and sleep services are deployed. For more information, see Preparations.

Procedure

  1. Check whether the service configurations take effect.

    1. In the kubeconfig environment for the ACK cluster, run the following command to start a bash session in the sleep environment.

      kubectl exec -it deploy/sleep -- sh
    2. Run the following command to send a request to the HTTPBin service:

      curl -I httpbin:8000

      Expected output:

      HTTP/1.1 200 OK
      Server: gunicorn/19.9.0
      Date: Mon, 28 Aug 2023 06:15:30 GMT
      Connection: keep-alive
      Content-Type: text/html; charset=utf-8
      Content-Length: 9593
      Access-Control-Allow-Origin: *
      Access-Control-Allow-Credentials: true
  2. Use the following content to configure a traffic rule for the HTTPBin service and add a direct response configuration. For more information, see Manage virtual services.

    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: httpbin-vs
      namespace: default
    spec:
      hosts:
        - httpbin.default.svc.cluster.local
      http:
        - directResponse:
            body:
              string: unknown error
            status: 503
  3. Check whether the direct response configuration takes effect.

    1. In the kubeconfig environment for the ACK cluster, run the following command to start a bash session in the sleep environment.

      kubectl exec -it -n default deploy/sleep -- sh
    2. Run the following command to send a request to the HTTPBin service:

      curl -I httpbin:8000

      Expected output:

      HTTP/1.1 503 Service Unavailable
      content-length: 13
      content-type: text/plain
      date: Thu, 10 Aug 2023 09:33:52 GMT
      server: istio-envoy
    3. Run the following command to send a request to the HTTPBin service:

      curl httpbin:8000

      Expected output:

      unknown error

      The output results indicate that the direct response configuration takes effect.