github.com/cilium/cilium@v1.16.2/Documentation/network/servicemesh/gateway-api/header.rst (about) 1 .. only:: not (epub or latex or html) 2 3 WARNING: You are looking at unreleased Cilium documentation. 4 Please use the official rendered version released here: 5 https://docs.cilium.io 6 7 .. _gs_gateway_header: 8 9 ***************************** 10 HTTP Header Modifier Examples 11 ***************************** 12 13 The Gateway can modify the headers of HTTP requests from clients. 14 15 .. include:: ../echo-app.rst 16 17 Deploy the Cilium Gateway 18 ========================= 19 20 HTTP header modification is the process of adding, removing, or modifying HTTP headers in incoming requests. 21 To configure HTTP header modification, define a Gateway object with one or more HTTP filters. Each filter specifies a specific modification to make to incoming requests, such as adding a custom header or modifying an existing header. 22 23 To add a header to a HTTP request, use a filter of the type ``RequestHeaderModifier`` with the ``add`` action and the name and value of the header. 24 25 You can find an example Gateway and HTTPRoute definition in ``request-header.yaml``: 26 27 .. literalinclude:: ../../../../examples/kubernetes/gateway/request-header.yaml 28 29 This example adds a header named ``my-header-name`` with the ``my-header-value`` value. 30 31 Deploy the Gateway and the HTTPRoute: 32 33 .. parsed-literal:: 34 35 $ kubectl apply -f \ |SCM_WEB|\/examples/kubernetes/gateway/request-header.yaml 36 37 The preceding kubectl command creates a Gateway named ``cilium-gw`` that listens on port 80. 38 39 .. code-block:: shell-session 40 41 $ kubectl get gateway cilium-gw 42 NAME CLASS ADDRESS PROGRAMMED AGE 43 cilium-gw cilium 172.18.255.200 8s 44 45 .. Note:: 46 47 Some providers like EKS use a fully-qualified domain name rather than an IP address. 48 49 Modify incoming HTTP Requests 50 ============================= 51 52 Now that the Gateway is ready, you can make HTTP requests. 53 54 .. code-block:: shell-session 55 56 $ curl -s http://$GATEWAY/add-a-request-header | grep -A 6 "Request Headers" 57 Request Headers: 58 accept=*/* 59 host=172.18.255.200 60 my-header-name=my-header-value 61 user-agent=curl/7.81.0 62 x-forwarded-proto=http 63 x-request-id=61a72702-3dfa-4bc3-a21c-7544ef36af7b 64 65 If the curl succeeds, you can see the HTTP Header from the incoming request in the body of the response sent back from the echo server. You can also see that the Gateway added the header. 66 67 You can also remove headers with the ``remove`` keyword and a list of header names. 68 69 .. code-block:: shell-session 70 71 filters 72 - type: RequestHeaderModifier 73 requestHeaderModifier: 74 remove: ["x-request-id"] 75 76 Notice that the ``x-request-id`` header is removed when you add the ``remove-a-request-header`` prefix match to the filter: 77 78 .. code-block:: shell-session 79 80 $ curl --fail -s http://$GATEWAY/remove-a-request-header | grep -A 6 "Request Headers" 81 Request Headers: 82 accept=*/* 83 host=172.18.255.200 84 user-agent=curl/7.81.0 85 x-forwarded-proto=http 86 87 To edit an existing header, use the ``set`` action to specify the value of the header to modify as well as the new header value to set. 88 89 .. code-block:: shell-session 90 91 filters: 92 - type: RequestHeaderModifier 93 requestHeaderModifier: 94 set: 95 - name: x-request-id 96 value: set-cilium-header-value 97 98 Notice that the ``x-request-id`` header is changed when you add the ``edit-a-request-header`` prefix match to the filter: 99 100 .. code-block:: shell-session 101 102 $ curl -s http://$GATEWAY/edit-a-request-header | grep -A 6 "Request Headers" 103 Request Headers: 104 accept=*/* 105 host=172.18.255.200 106 user-agent=curl/7.81.0 107 x-forwarded-proto=http 108 x-request-id=set-cilium-header-value