[Header manipulation] Request/response header transformation
Before a request or response is forwarded, request and response headers can be added or removed. To modify the headers of a request or response without changing the application code, use a virtual service. This topic describes how to configure request/response header transformation.
Prerequisites
The preparations are complete, and the httpbin and sleep services are deployed. For instructions, see Preparations.
Procedure
Verify whether the service configuration takes effect.
In the KubeConfig environment of the ACK cluster, run the following command to enter the sleep environment and start bash.
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 the traffic rules of the httpbin application and add the configuration for modifying headers. For instructions, see Manage virtual services.
Verify whether the configuration takes effect.
In the KubeConfig environment of the ACK cluster, run the following command to enter the sleep environment and start bash.
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 expected output indicates that the header configuration in the virtual service has taken effect: the
x-envoy-upstream-service-timefield is removed andhttpbin: hellois 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