This episode covers header manipulation, redirects, rewrites, and prefix matching, conditional routing with route rules, and gRPC and WebSocket protocol support through the gateway.

You've mastered basic routing. Now it's time to manipulate the request itself. Episode 8 covers advanced routing and request transformation: modifying headers, redirecting and rewriting paths, evaluating complex routing conditions, and serving non-HTTP protocols like gRPC and WebSocket.
The RequestHeaderModifier filter adds, changes, or removes headers before the request reaches the backend:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: api-route
spec:
parentRefs:
- name: main-gateway
namespace: multigress-system
rules:
- backendRefs:
- name: api
port: 8080
filters:
- type: RequestHeaderModifier
requestHeaderModifier:
set:
- name: X-Forwarded-For
value: "true"
add:
- name: X-Client-Region
value: "id"
remove:
- "X-Internal-Token"With the filter above, the proxy adds the X-Client-Region header before forwarding to the api Service. The kubectl apply -f route.yaml command applies this transformation immediately, with no backend restart needed.
There are two filters that look similar at first glance but serve different purposes:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: https-redirect
spec:
parentRefs:
- name: main-gateway
namespace: multigress-system
rules:
- filters:
- type: RequestRedirect
requestRedirect:
scheme: https
statusCode: 301The route above changes all HTTP requests to HTTPS. And for rewriting an old path to a new one:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: rewrite-route
spec:
rules:
- matches:
- path:
type: PathPrefix
value: /api/v2
filters:
- type: URLRewrite
urlRewrite:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /v2
backendRefs:
- name: api
port: 8080A request to /api/v2/users will be forwarded as /v2/users to the backend. With ReplacePrefixMatch, the backend doesn't need to know the old path was named v2.
HTTPRoute rules can be conditioned on more than just path. The following combination routes requests based on header and method:
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: booking-route
spec:
parentRefs:
- name: main-gateway
rules:
- matches:
- headers:
- type: Exact
name: X-Canary
value: "true"
method: GET
backendRefs:
- name: booking-canary
port: 8080
- backendRefs:
- name: booking-stable
port: 8080Clients that send the X-Canary: true header with the GET method are routed to booking-canary; everyone else goes to booking-stable. This is the header-based canary pattern often used for internal testing.
Some important rules about matching:
method and queryParams are also available as conditions.gRPC uses HTTP/2 and method terms like /service.Method. Its route uses GRPCRoute with matching based on service and method:
apiVersion: gateway.networking.k8s.io/v1
kind: GRPCRoute
metadata:
name: grpc-route
spec:
parentRefs:
- name: main-gateway
namespace: multigress-system
hostnames:
- "grpc.example.com"
rules:
- matches:
- method:
type: Exact
service: com.example.payment.PaymentService
method: Charge
backendRefs:
- name: payment-grpc
port: 9000GRPCRoute uses the same structure as HTTPRoute, only its matching is based on gRPC service and method.
WebSocket doesn't need a special route — its handshake is a regular HTTP request with an upgrade header. As long as the HTTPRoute points to the right Service, the upgrade will be forwarded, and a 101 Switching Protocols status indicates the connection was successfully upgraded.
Info
Make sure the timeout policy in BackendTrafficPolicy isn't too short for WebSocket — connections can last a long time, and the standard request timeout would cut them off.
Episode 8 completes your routing capabilities: header transformation, redirects and rewrites, conditional routing based on headers and methods, and gRPC and WebSocket protocol support that flows smoothly through the gateway.
The key takeaways:
In the next episode 9 we'll discuss canary deployments & progressive delivery — traffic shifting with weights, observability feedback loops for deployment safety, and integration with Argo Rollouts and Flagger. The route rules you just learned will become the primary tool in this episode.