Skip to content

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

Page as Markdown

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.processingMode field sets the mode for all routes that use this ExtProc server.
  • TrafficPolicy: The extProc.processingMode field sets a different mode for the routes that the policy applies to.
  • ExtProc server: If you set extProc.allowProcessingModeOverride in 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.

FieldDefaultValues
requestHeaderModeSENDSEND, SKIP, or DEFAULT
responseHeaderModeSENDSEND, SKIP, or DEFAULT
requestBodyModeNONENONE, STREAMED, BUFFERED, BUFFERED_PARTIAL, or FULL_DUPLEX_STREAMED
responseBodyModeNONENONE, STREAMED, BUFFERED, BUFFERED_PARTIAL, or FULL_DUPLEX_STREAMED
requestTrailerModeSKIPSEND, SKIP, or DEFAULT
responseTrailerModeSKIPSEND, 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 modeDescription
NONEDo not send the body.
STREAMEDSend the body to the ExtProc server in chunks as they arrive.
BUFFEREDBuffer 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_PARTIALBuffer the body up to the buffer limit, and send what was buffered in one message. Larger bodies are not rejected.
FULL_DUPLEX_STREAMEDStream 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: SKIP

Override 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

  1. Follow the Get started guide to install kgateway.

  2. Follow the Sample app guide to create a gateway proxy with an HTTP listener and deploy the httpbin sample app.

  3. 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  

  1. Deploy the sample ExtProc server as shown in Set up an ExtProc server. The sample server reads instructions from an instructions header 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.

  1. Create a GatewayExtension for the ExtProc server. The processingMode field explicitly sets the default mode, which sends the request headers and the response headers to the ExtProc server.

    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
    EOF
    Review the following table to understand this configuration.
    SettingDescription
    spec.extProc.grpcService.backendRefThe Service of the sample ExtProc server that you deployed before you began.
    spec.extProc.processingMode.requestHeaderModeSet to SEND to send the request headers to the ExtProc server.
    spec.extProc.processingMode.responseHeaderModeSet to SEND to send the response headers to the ExtProc server.
  2. Create an HTTPRoute for the httpbin app on the extproc-modes.example domain.

    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
    EOF
  3. Create 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
    EOF
  4. Create 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
    EOF
  5. Send a request to the /response-headers path of the httpbin app. The httpbin app returns each query parameter as a response header, so the response includes an instructions header that tells the ExtProc server to add the extproc-response: true header. Verify that the response includes the extproc-response: true header. 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
    ...
    
  6. Update the TrafficPolicy to skip the response headers for the route. Because the mode in the TrafficPolicy replaces the mode in the GatewayExtension, requestHeaderMode gets its default value of SEND, and the request headers are still sent to the ExtProc server.

    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
    EOF
    Review the following table to understand this configuration.
    SettingDescription
    spec.extProc.processingMode.responseHeaderModeSet to SKIP to stop sending the response headers for this route. The other fields get their default values, not the values from the GatewayExtension.
  7. Repeat the request. Verify that the response still includes the instructions header, but no extproc-response header, 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
    ...
    
  8. Send a request to the /headers path with instructions in the request headers. Verify that the Extproc-Request header 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: BUFFERED

Note

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
Was this page helpful?