Skip to content
Latest (currently 2026.10.2) has the newest features, bug fixes, and CVE patches of Solo Enterprise for agentgateway.

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Rewrite path and method

Page as Markdown

Conditionally rewrite the request path and HTTP method using CEL ternary expressions.

Change the request path and HTTP method when a request header is present by using CEL expressions. The example uses request.headers[], request.path, and request.method with a ternary expression to conditionally set the :path and :method pseudo headers.

About pseudo headers

Pseudo headers are special headers that are used in HTTP/2 to provide metadata about the request or response in a structured way. Although they look like traditional HTTP/1.x headers, they come with specific characteristics:

  • Must always start with a colon (:).
  • Must appear before regular headers in the HTTP/2 frame.
  • Contain details about the request or response.

Common pseudo headers include:

  • :method: The HTTP method that is used, such as GET or POST.
  • :scheme: The protocol that is used, such as http or https.
  • :authority: The hostname and port number that the request is sent to.
  • :path: The path of the request.

Before you begin

  1. Set up an agentgateway proxy.
  2. Install the httpbin sample app.

Update request paths and HTTP methods

  1. Create an EnterpriseAgentgatewayPolicy resource with your transformation rules. The policy rewrites the path to /post and the method to POST when the foo: bar request header is present. When the header is absent, the path and method are unchanged.

    kubectl apply -f- <<EOF
    apiVersion: enterpriseagentgateway.solo.io/v1alpha1
    kind: EnterpriseAgentgatewayPolicy
    metadata:
      name: transformation
      namespace: httpbin
    spec:
      targetRefs:
      - group: gateway.networking.k8s.io
        kind: HTTPRoute
        name: httpbin
      traffic:
        transformation:
          request:
            set:
            - name: ":path"
              value: 'request.headers["foo"] == "bar" ? "/post" : request.path'
            - name: ":method"
              value: 'request.headers["foo"] == "bar" ? "POST" : request.method'
    EOF
  2. Send a request to the /get endpoint and include the foo: bar header to trigger the transformation. Verify that you get back a 200 HTTP response code. The httpbin /post endpoint only accepts POST requests, so a 200 response confirms both the path rewrite and the method change succeeded.

    curl -vi http://$INGRESS_GW_ADDRESS:80/get \
     -H "foo: bar" \
     -H "host: www.example.com:80"
    curl -vi localhost:8080/get \
    -H "foo: bar" \
    -H "host: www.example.com"

    Example output:

    < HTTP/1.1 200 OK
    HTTP/1.1 200 OK
    ...
    {
      "args": {},
      "headers": {
         "Accept": [
           "*/*"
         ],
         "Content-Length": [
         "0"
         ],
         "Foo": [
         "bar"
         ],
         "Host": [
         "www.example.com:8080"
         ],
         "User-Agent": [
         "curl/7.77.0"
         ]
     },
     "origin": "127.0.0.6:48539",
     "url": "http://www.example.com:8080/post",
     "data": "",
     "files": null,
     "form": null,
     "json": null
    }
    
  3. Send another request to the /get endpoint. This time, omit the foo: bar header. Verify that you get back a 200 HTTP response code and that the request path is not rewritten.

    curl -vi http://$INGRESS_GW_ADDRESS:80/get \
     -H "host: www.example.com:80"
    curl -vi localhost:8080/get \
    -H "host: www.example.com"

    Example output:

    < HTTP/1.1 200 OK
    HTTP/1.1 200 OK
    ...
    
    {
     "args": {},
     "headers": {
         "Accept": [
         "*/*"
         ],
         "Host": [
         "www.example.com:8080"
         ],
         "User-Agent": [
         "curl/7.77.0"
         ]
     },
     "origin": "127.0.0.6:46209",
     "url": "http://www.example.com:8080/get"
    }
    

Cleanup

You can remove the resources that you created in this guide.
kubectl delete EnterpriseAgentgatewayPolicy transformation -n httpbin