modify response headers
With Istio, you can apply traffic rules to route based on HTTP request headers. You can also use Istio to modify response headers. This could be useful if you want to strip headers generated by your application, or if you want to add response headers without changing your application code.
In this example, we will apply an Istio VirtualService to add a new header (
hello:world), then remove the
set-cookie header. Then, all client requests entering the service mesh through the
default gateway will receive those modified headers.
apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: frontend-ingress spec: hosts: - "*" gateways: - frontend-gateway http: - route: - destination: host: frontend port: number: 80 headers: response: add: hello: world remove: - "set-cookie"
Before we apply the VirtualService, the
frontend service returns the following response headers:
HTTP/1.1 200 OK set-cookie: shop_session-id=432bef95-0d25-4754-80c8-3904c2e329e9; Max-Age=172800 date: Wed, 18 Sep 2019 16:26:01 GMT content-type: text/html; charset=utf-8 x-envoy-upstream-service-time: 45 server: istio-envoy transfer-encoding: chunked
Then when we
kubectl apply the VirtualService, we see that Envoy is successfully configured to modify the response headers:
HTTP/1.1 200 OK date: Wed, 18 Sep 2019 16:26:24 GMT content-type: text/html; charset=utf-8 x-envoy-upstream-service-time: 85 hello: world server: istio-envoy transfer-encoding: chunked