You can add or remove request and response headers before requests are forwarded. A virtual service lets you modify headers without changing your application code. This topic describes how to configure request and response header manipulation.
Prerequisites
Make sure that you have completed the preparations and deployed the httpbin and sleep services. For more information, see Preparations.
Procedure
Verify the service configuration.
In the KubeConfig environment for your ACK cluster, run the following command to enter the sleep environment and start a bash session.
kubectl exec -it deploy/sleep -- shRun the following command to send a request to the httpbin service.
curl -I httpbin:8000Expected output:
HTTP/1.1 200 OK server: envoy date: Fri, 11 Aug 2023 09:50:24 GMT content-type: text/html; charset=utf-8 content-length: 9593 access-control-allow-origin: * access-control-allow-credentials: true x-envoy-upstream-service-time: 3
Use the following content to configure traffic rules for the httpbin application and add a header modification configuration. For more information, see Manage virtual services.
Verify the configuration.
In the KubeConfig environment for your ACK cluster, run the following command to enter the sleep environment and start a bash session.
kubectl exec -it deploy/sleep -- shRun the following command to send a request to the httpbin service.
curl -I httpbin:8000Expected output:
HTTP/1.1 200 OK server: envoy date: Fri, 11 Aug 2023 09:49:37 GMT content-type: text/html; charset=utf-8 content-length: 9593 access-control-allow-origin: * access-control-allow-credentials: true httpbin: helloThe output shows that the header configuration in the virtual service has taken effect. The
x-envoy-upstream-service-timeheader is removed, and thehttpbin: helloheader is added.
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: httpbin-vs
namespace: default
spec:
hosts:
- httpbin
http:
- route:
- destination:
host: httpbin
headers:
response:
add:
httpbin: hello
remove:
- x-envoy-upstream-service-time