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
- Set up an agentgateway proxy.
- 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.
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 EOFSetting Description maxBufferSizeThe maximum size of HTTP body that can be buffered into memory. Port-forward the gateway proxy on port 15000.
kubectl port-forward deployment/agentgateway-proxy -n agentgateway-system 15000Get the config dump and verify that the policy is set as you configured it.
Example
jqcommand: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_dump1 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