A Gateway API filter is a route-rule operation that processes traffic after matching and before or after backend handling. It can modify requests or responses, rewrite URLs, redirect clients, mirror traffic, or invoke an implementation-specific extension. section 13.3.4
Common filter operations include:
- RequestHeaderModifier adds, removes, or changes request headers; add appends values, while set replaces them. section 13.3.4
- ResponseHeaderModifier applies add, set, and remove operations to headers returned by the backend. section 13.3.4
- URLRewrite replaces the full request path or the prefix matched by a PathPrefix rule, and can change the hostname. section 13.3.4
- RequestRedirect sends the client elsewhere without routing the request to a backend, such as redirecting HTTP traffic to HTTPS on port 443. section 13.3.4
- RequestMirror forwards a copy of traffic to another service while the primary backend continues handling the request. section 13.3.4
- ExtensionRef selects a custom filter whose behavior depends on the Gateway implementation. section 13.3.4
Rewriting a matched path
A rule matching paths beginning with /foo can use URLRewrite with ReplaceFullPath to send the backend a request for /new/path and the hostname newhost.kiada.example.com.
Mirroring traffic
A rule can route requests to kiada-stable while mirroring copies to kiada-new. Curl output and pod logs show both services receiving the request.
Listing 13.8 Modifying request headers
spec:
rules:
- backendRefs:
- name: kiada-stable
port: 80
filters: #1
- type: RequestHeaderModifier #2
requestHeaderModifier: #3
add: #4
- name: added-by-gateway #4
value: This header was added via requestHeaderModifier #4
remove: #5
- RemoveMe #5
set: #6
- name: set-by-gateway #6
value: This header was set via requestHeaderModifier #6
Inspect the complete HTTPRoute configuration for adding, removing, and replacing request headers. section 13.3.4
Listing 13.12 Redirecting a request
rules:
- filters:
- type: RequestRedirect #1
requestRedirect: #2
scheme: https #3
port: 443 #4
statusCode: 301 #5
Inspect a redirect rule that changes the scheme to HTTPS, selects port 443, and returns status 301. section 13.3.4
GRPCRoute rules support RequestHeaderModifier, ResponseHeaderModifier, RequestMirror, and ExtensionRef. These filters behave like their HTTPRoute counterparts; URL rewriting and redirects are not listed among the currently available gRPC filters. section 13.5.3


