sigs.k8s.io/gateway-api@v1.0.0/site-src/guides/http-header-modifier.md (about)

     1  # HTTP Header Modifiers
     2  
     3  [HTTPRoute resources](/api-types/httproute) can modify the headers of HTTP requests and the HTTP responses from clients. 
     4  There are two types of [filters](/api-types/httproute#filters-optional) available to meet these requirements: `RequestHeaderModifier` and `ResponseHeaderModifier`.
     5  
     6  This guide shows how to use these features.
     7  
     8  Note that these features are compatible. HTTP headers of the incoming requests and the headers of their responses can both be modified using a single [HTTPRoute resource](/api-types/httproute).
     9  
    10  ## HTTP Request Header Modifier
    11  
    12  HTTP header modification is the process of adding, removing, or modifying HTTP headers in incoming requests. 
    13  
    14  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.
    15  
    16  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:
    17  
    18  ```yaml
    19  {% include 'standard/http-request-header-add.yaml' %}
    20  ```
    21  
    22  To edit an existing header, use the `set` action and specify the value of the header to be modified and the new header value to be set.
    23  
    24  ```yaml
    25      filters:
    26      - type: RequestHeaderModifier
    27        requestHeaderModifier:
    28          set: 
    29            - name: my-header-name
    30              value: my-new-header-value
    31  ```
    32  
    33  Headers can also be removed, by using the `remove` keyword and a list of header names. 
    34  
    35  ```yaml
    36      filters:
    37      - type: RequestHeaderModifier
    38        requestHeaderModifier:
    39          remove: ["x-request-id"]
    40  ```
    41  
    42  Using the example above would remove the `x-request-id` header from the HTTP request.
    43  
    44  ### HTTP Response Header Modifier
    45  
    46  Just like editing request headers can be useful, the same goes for response headers. For example, it allows teams to add/remove cookies for only a certain backend, which can help in identifying certain users that were redirected to that backend previously.
    47  
    48  Another potential use case could be when you have a frontend that needs to know whether it’s talking to a stable or a beta version of the backend server, in order to render different UI or adapt its response parsing accordingly.
    49  
    50  Modifying the HTTP header response leverages a very similar syntax to the one used to modify the original request, albeit with a different filter (`ResponseHeaderModifier`).
    51  
    52  Headers can be added, edited and removed. Multiple headers can be added, as shown in this example below:
    53  
    54  ```yaml
    55      filters:
    56      - type: ResponseHeaderModifier
    57        responseHeaderModifier:
    58          add:
    59          - name: X-Header-Add-1
    60            value: header-add-1
    61          - name: X-Header-Add-2
    62            value: header-add-2
    63          - name: X-Header-Add-3
    64            value: header-add-3
    65  ```