Buffering

Verified Code examples on this page have been automatically tested and verified.

Fine-tune connection speeds for read and write operations by setting a connection buffer limit.

About buffer limits

By default, agentgateway allows up to 2mb of HTTP body to be buffered into memory for each gateway. For large requests that must be buffered and that exceed the default buffer limit, agentgateway either disconnects the connection to the downstream service if headers were already sent, or returns a 413 HTTP response code. To make sure that large requests can be sent and received, you can specify the maximum number of bytes that can be buffered between the gateway and the downstream service. Alternatively, when using agentgateway as an edge proxy, configuring the buffer limit can be important when dealing with untrusted downstreams. By setting the limit to a small number, such as 32768 bytes (32KiB), you can better guard against potential attacks or misconfigured downstreams that could excessively use the proxy’s resources.

The buffer limit is configured at the Gateway level via a AgentgatewayPolicy.

Before you begin

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

Set up buffer limits per gateway

Use a AgentgatewayPolicy to set a buffer limit on your Gateway, which applies to all routes served by the Gateway.

  1. Create an AgentgatewayPolicy that sets the maximum HTTP body buffer size.

    kubectl apply -f- <<EOF
    apiVersion: agentgateway.dev/v1alpha1
    kind: AgentgatewayPolicy
    metadata:
      name: maxbuffer
      namespace: agentgateway-system
    spec:
      targetRefs:
      - kind: Gateway
        name: agentgateway-proxy
        group: gateway.networking.k8s.io
      frontend:
        http:
          maxBufferSize: 2097152
    EOF
    SettingDescription
    maxBufferSizeThe maximum size of HTTP body that can be buffered into memory.
  2. Port-forward the gateway proxy on port 15000.

    kubectl port-forward deployment/agentgateway-proxy -n agentgateway-system 15000
  3. Get the config dump and verify that the policy is set as you configured it.

    Example jq command:

    curl -s http://localhost:15000/config_dump | jq '[.policies[] | select(.policy.frontend != null and .policy.frontend.hTTP != null and .policy.frontend.hTTP.maxBufferSize != null)] | .[0]'

    Example output:

    http://localhost:15000/config_dump
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    {
      "key": "frontend/agentgateway-system/maxbuffer:frontend-http:agentgateway-system/agentgateway-proxy",
      "name": {
        "kind": "AgentgatewayPolicy",
        "name": "maxbuffer",
        "namespace": "agentgateway-system"
      },
      "target": {
        "gateway": {
         "gatewayName": "agentgateway-proxy",
         "gatewayNamespace": "agentgateway-system",
         "listenerName": null
       }
     },
     "policy": {
       "frontend": {
         "hTTP": {
           "maxBufferSize": 2097152,
           "http1MaxHeaders": null,
           "http1IdleTimeout": null,
           "http2WindowSize": null,
           "http2ConnectionWindowSize": null,
           "http2FrameSize": null,
           "http2KeepaliveInterval": null,
           "http2KeepaliveTimeout": null
         }
       }
     }
    }

Cleanup

You can remove the resources that you created in this guide.
kubectl delete AgentgatewayPolicy maxbuffer -n agentgateway-system
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.