For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
ExtProc processing modes
Control which parts of a request and response the gateway sends to an ExtProc server, and override the mode for specific routes.
Use processing modes to control which parts of a request and response the gateway sends to your ExtProc server, such as headers, bodies, and trailers.
About processing modes
By default, the gateway proxy sends only the request headers and the response headers to the ExtProc server. Bodies and trailers pass through the gateway without being sent to the ExtProc server. With a processing mode, you can change this behavior for each of the six parts of an HTTP exchange. For example, you might send the request body so that your ExtProc server can inspect or rewrite the payload, or skip the response headers if your server only works on requests. Each part that you skip saves a round trip to the ExtProc server.
You can set the processing mode in the following places:
- GatewayExtension: The
extProc.processingModefield sets the mode for all routes that use this ExtProc server. - TrafficPolicy: The
extProc.processingModefield sets a different mode for the routes that the policy applies to. - ExtProc server: If you set
extProc.allowProcessingModeOverridein the GatewayExtension, the ExtProc server can change the mode for a single request. For more information, see Let the ExtProc server change the mode.
Processing mode fields
The following table describes the fields of a processing mode. If you omit a field, the default value is used.
| Field | Default | Values |
|---|---|---|
requestHeaderMode | SEND | SEND, SKIP, or DEFAULT |
responseHeaderMode | SEND | SEND, SKIP, or DEFAULT |
requestBodyMode | NONE | NONE, STREAMED, BUFFERED, BUFFERED_PARTIAL, or FULL_DUPLEX_STREAMED |
responseBodyMode | NONE | NONE, STREAMED, BUFFERED, BUFFERED_PARTIAL, or FULL_DUPLEX_STREAMED |
requestTrailerMode | SKIP | SEND, SKIP, or DEFAULT |
responseTrailerMode | SKIP | SEND, SKIP, or DEFAULT |
For headers and trailers, SEND sends that part to the ExtProc server, and SKIP does not. DEFAULT uses Envoy’s default, which sends headers and skips trailers. In a TrafficPolicy, DEFAULT also means Envoy’s default, not the value from the GatewayExtension.
For bodies, choose one of the following modes.
| Body mode | Description |
|---|---|
NONE | Do not send the body. |
STREAMED | Send the body to the ExtProc server in chunks as they arrive. |
BUFFERED | Buffer the entire body in the gateway proxy, and send it in one message. If the body is larger than the buffer limit, the gateway proxy returns an error. |
BUFFERED_PARTIAL | Buffer the body up to the buffer limit, and send what was buffered in one message. Larger bodies are not rejected. |
FULL_DUPLEX_STREAMED | Stream the body to the ExtProc server in chunks as they arrive. The ExtProc server can buffer chunks and send its processed chunks back at any time. You must also set the matching trailer mode, such as requestTrailerMode for requestBodyMode, to SEND. Otherwise, the gateway proxy rejects the configuration for the entire listener and keeps its previous configuration, even though the resource status shows Accepted. |
For more information, see the Envoy processing mode reference.
Set the mode for all routes
To change the mode for every route that uses an ExtProc server, set processingMode in the GatewayExtension. The following example sends the request body to the ExtProc server after the gateway proxy buffers it, and skips the response headers.
apiVersion: gateway.kgateway.dev/v1alpha1
kind: GatewayExtension
metadata:
name: ext-proc-extension
namespace: kgateway-system
spec:
type: ExtProc
extProc:
grpcService:
backendRef:
name: ext-proc-grpc
port: 4444
processingMode:
requestBodyMode: BUFFERED
responseHeaderMode: SKIPOverride the mode for specific routes
To use a different mode for some routes, set extProc.processingMode in the TrafficPolicy that applies the ExtProc server to those routes. The mode in the TrafficPolicy applies to these routes, even if allowProcessingModeOverride is not set in the GatewayExtension.
Important
The mode in the TrafficPolicy replaces the mode in the GatewayExtension as a whole. Fields are not merged. Any field that you omit in the TrafficPolicy gets its default value from the processing mode fields table, not the value from the GatewayExtension. For example, if the GatewayExtension in the previous example skips response headers and a TrafficPolicy sets only requestBodyMode: STREAMED, the response headers on the routes of that policy are sent to the ExtProc server again. To keep a setting from the GatewayExtension, repeat it in the TrafficPolicy.
Before you begin
Follow the Get started guide to install kgateway.
Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.
Get the external address of the gateway and save it in an environment variable.
export INGRESS_GW_ADDRESS=$(kubectl get svc -n kgateway-system http -o jsonpath="{.status.loadBalancer.ingress[0]['hostname','ip']}") echo $INGRESS_GW_ADDRESS
- Deploy the sample ExtProc server as shown in Set up an ExtProc server. The sample server reads instructions from an
instructionsheader in the request headers and in the response headers, and adds or removes headers as instructed. The sample server does not process bodies, so this guide uses the header modes only.
Skip the response headers on a route
In this example, you apply an ExtProc server to a route and check that the server processes both the request headers and the response headers. Then, you use a TrafficPolicy to stop sending the response headers for that route.
Create a GatewayExtension for the ExtProc server. The
processingModefield explicitly sets the default mode, which sends the request headers and the response headers to the ExtProc server.Review the following table to understand this configuration.kubectl apply -f- <<EOF apiVersion: gateway.kgateway.dev/v1alpha1 kind: GatewayExtension metadata: name: ext-proc-modes namespace: kgateway-system spec: type: ExtProc extProc: grpcService: backendRef: name: ext-proc-grpc port: 4444 processingMode: requestHeaderMode: SEND responseHeaderMode: SEND EOFSetting Description spec.extProc.grpcService.backendRefThe Service of the sample ExtProc server that you deployed before you began. spec.extProc.processingMode.requestHeaderModeSet to SENDto send the request headers to the ExtProc server.spec.extProc.processingMode.responseHeaderModeSet to SENDto send the response headers to the ExtProc server.Create an HTTPRoute for the httpbin app on the
extproc-modes.exampledomain.kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: extproc-modes namespace: kgateway-system spec: parentRefs: - name: http namespace: kgateway-system hostnames: - "extproc-modes.example" rules: - backendRefs: - name: httpbin port: 8000 namespace: httpbin EOFCreate a ReferenceGrant to allow the HTTPRoute to forward traffic to the httpbin app. This resource is required because the HTTPRoute and the httpbin app are in different namespaces. If you already created this ReferenceGrant in the header manipulation guide, you can skip this step.
kubectl apply -f- <<EOF apiVersion: gateway.networking.k8s.io/v1beta1 kind: ReferenceGrant metadata: name: allow-httproute-to-httpbin namespace: httpbin spec: from: - group: gateway.networking.k8s.io kind: HTTPRoute namespace: kgateway-system to: - group: "" kind: Service EOFCreate a TrafficPolicy that applies the ExtProc server to the HTTPRoute.
kubectl apply -f- <<EOF apiVersion: gateway.kgateway.dev/v1alpha1 kind: TrafficPolicy metadata: name: extproc-modes namespace: kgateway-system spec: targetRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: extproc-modes extProc: extensionRef: name: ext-proc-modes EOFSend a request to the
/response-headerspath of the httpbin app. The httpbin app returns each query parameter as a response header, so the response includes aninstructionsheader that tells the ExtProc server to add theextproc-response: trueheader. Verify that the response includes theextproc-response: trueheader. This header shows that the ExtProc server processed the response headers.curl -i -G http://$INGRESS_GW_ADDRESS:8080/response-headers -H "host: extproc-modes.example" \ --data-urlencode 'instructions={"addHeaders":{"extproc-response":"true"}}'Example output:
HTTP/1.1 200 OK access-control-allow-credentials: true access-control-allow-origin: * content-type: application/json; encoding=utf-8 instructions: {"addHeaders":{"extproc-response":"true"}} ... extproc-response: true server: envoy ...Update the TrafficPolicy to skip the response headers for the route. Because the mode in the TrafficPolicy replaces the mode in the GatewayExtension,
requestHeaderModegets its default value ofSEND, and the request headers are still sent to the ExtProc server.Review the following table to understand this configuration.kubectl apply -f- <<EOF apiVersion: gateway.kgateway.dev/v1alpha1 kind: TrafficPolicy metadata: name: extproc-modes namespace: kgateway-system spec: targetRefs: - group: gateway.networking.k8s.io kind: HTTPRoute name: extproc-modes extProc: extensionRef: name: ext-proc-modes processingMode: responseHeaderMode: SKIP EOFSetting Description spec.extProc.processingMode.responseHeaderModeSet to SKIPto stop sending the response headers for this route. The other fields get their default values, not the values from the GatewayExtension.Repeat the request. Verify that the response still includes the
instructionsheader, but noextproc-responseheader, because the response headers are no longer sent to the ExtProc server.curl -i -G http://$INGRESS_GW_ADDRESS:8080/response-headers -H "host: extproc-modes.example" \ --data-urlencode 'instructions={"addHeaders":{"extproc-response":"true"}}'Example output:
HTTP/1.1 200 OK access-control-allow-credentials: true access-control-allow-origin: * content-type: application/json; encoding=utf-8 instructions: {"addHeaders":{"extproc-response":"true"}} ... server: envoy ...Send a request to the
/headerspath with instructions in the request headers. Verify that theExtproc-Requestheader is in the request headers that the httpbin app received, which shows that the ExtProc server still processes the request headers.curl -s http://$INGRESS_GW_ADDRESS:8080/headers -H "host: extproc-modes.example" \ -H 'instructions: {"addHeaders":{"extproc-request":"true"}}'Example output:
{ "headers": { "Accept": [ "*/*" ], "Extproc-Request": [ "true" ], ...
Let the ExtProc server change the mode
An ExtProc server can decide for each request whether it needs more of the request or response. For example, the server might check the content-type request header and request the body only for JSON payloads. To do that, the server sets the mode_override field in its response to the request headers or the response headers. The new mode applies to the rest of that request and its response only. To change how the request body is processed, the server must send mode_override with its response to the request headers.
The gateway proxy ignores mode_override unless you set allowProcessingModeOverride: true in the GatewayExtension. To limit the modes that the server can switch to, list them in allowedProcessingModeOverrides. The gateway proxy then ignores a mode_override that does not match one of the listed modes. If you omit the list, the server can switch to any mode.
Each mode in the list gets the default values from the processing mode fields table for the fields that you omit. The gateway proxy fills the header and trailer fields that the mode_override leaves at DEFAULT with the values from the processingMode of the GatewayExtension, and then compares the result with the list. The result must match one of the listed modes in every field except requestHeaderMode. The following example lets the ExtProc server turn on buffered request body processing. Because this GatewayExtension does not set processingMode, the fields that the server omits stay at DEFAULT and do not match the listed mode. To match, the server must send a mode_override that sets requestBodyMode to BUFFERED, responseHeaderMode to SEND, and both trailer modes to SKIP. If you set processingMode in the GatewayExtension, the omitted fields come from that mode instead.
apiVersion: gateway.kgateway.dev/v1alpha1
kind: GatewayExtension
metadata:
name: ext-proc-extension
namespace: kgateway-system
spec:
type: ExtProc
extProc:
grpcService:
backendRef:
name: ext-proc-grpc
port: 4444
allowProcessingModeOverride: true
allowedProcessingModeOverrides:
- requestBodyMode: BUFFEREDNote
The ExtProc server cannot override the mode if the processingMode in the GatewayExtension sets a body mode to FULL_DUPLEX_STREAMED. A mode that you set in a TrafficPolicy does not depend on these settings.
For more information, see allow_mode_override and allowed_override_modes in the Envoy documentation.
Cleanup
You can remove the resources that you created in this guide.kubectl delete trafficpolicy extproc-modes -n kgateway-system
kubectl delete httproute extproc-modes -n kgateway-system
kubectl delete gatewayextension ext-proc-modes -n kgateway-system