HTTP connection settings
Verified Code examples on this page have been automatically tested and verified.You can use an AgentgatewayPolicy to apply HTTP connection settings to the agentgateway proxy. These settings include idle connection timeouts, the maximum number of connections that an upstream service can receive, and more. Note that these options are applied to HTTP/1 or HTTP/2 requests only when indicated.
Before you begin
- Set up an agentgateway proxy.
- Install the httpbin sample app.
Maximum buffer size
Fine-tune connection speeds for read and write operations by setting a connection buffer limit (maxBufferSize). You can use this setting for both HTTP/1 and HTTP/2 connections.
HTTP/1.1 settings
Use these settings to control header limits and idle connection behavior for HTTP/1.1 connections.
Idle timeouts
Set an idle timeout for HTTP/1 traffic to terminate the connection to a downstream or upstream service if there are no active streams.
Max headers
Set the maximum number of headers allowed in HTTP/1.1 requests.
Create an AgentgatewayPolicy that applies the HTTP/1.1 connection configuration to the proxy.
kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayPolicy metadata: name: http1 namespace: agentgateway-system spec: targetRefs: - kind: Gateway name: agentgateway-proxy group: gateway.networking.k8s.io frontend: http: http1MaxHeaders: 15 EOFSetting Description http1MaxHeadersThe maximum number of headers allowed in HTTP/1.1 requests. Requests that exceed the limit receive a 431 response. 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.http1IdleTimeout != 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/http1:frontend-http:agentgateway-system/agentgateway-proxy", "name": { "kind": "AgentgatewayPolicy", "name": "http1", "namespace": "agentgateway-system" }, "target": { "gateway": { "gatewayName": "agentgateway-proxy", "gatewayNamespace": "agentgateway-system", "listenerName": null } }, "policy": { "frontend": { "hTTP": { "maxBufferSize": null, "http1MaxHeaders": 15, "http1IdleTimeout": null, "http2WindowSize": null, "http2ConnectionWindowSize": null, "http2FrameSize": null, "http2KeepaliveInterval": null, "http2KeepaliveTimeout": null } } } }
- Optional: Clean up and remove the AgentgatewayPolicy.
kubectl delete AgentgatewayPolicy http1 -n agentgateway-systemHTTP/2 settings
Use these settings to tune HTTP/2 flow control, which governs how much data can be in-flight at the stream and connection levels.
Flow control
Create an AgentgatewayPolicy that applies HTTP/2 flow control configuration to the proxy.
kubectl apply -f- <<EOF apiVersion: agentgateway.dev/v1alpha1 kind: AgentgatewayPolicy metadata: name: http2-flow namespace: agentgateway-system spec: targetRefs: - kind: Gateway name: agentgateway-proxy group: gateway.networking.k8s.io frontend: http: http2WindowSize: 1048576 http2ConnectionWindowSize: 4194304 http2FrameSize: 65536 EOFSetting Description http2WindowSizeControls how many bytes can be in-flight on a single HTTP/2 stream before the sender must wait for a WINDOW_UPDATEacknowledgment. Setting this to 1 means the client can only send 1 byte at a time per stream, essentially halting all throughput. The default is 65,535 bytes (64KB).http2ConnectionWindowSizeThe initial window size for connection-level flow control for received data. This settings controls the total bytes in-flight across all streams on a single connection combined. http2FrameSizeThe maximum size of a single HTTP/2 DATA frame the gateway accepts. The HTTP/2 protocol minimum (and default) is 16,384 bytes. 17000 is a modest bump above that default, allowing slightly larger frames and potentially fewer round-trips for larger payloads. 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.http2WindowSize != 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/http2-flow:frontend-http:agentgateway-system/agentgateway-proxy", "name": { "kind": "AgentgatewayPolicy", "name": "http2-flow", "namespace": "agentgateway-system" }, "target": { "gateway": { "gatewayName": "agentgateway-proxy", "gatewayNamespace": "agentgateway-system", "listenerName": null } }, "policy": { "frontend": { "hTTP": { "maxBufferSize": null, "http1MaxHeaders": null, "http1IdleTimeout": null, "http2WindowSize": 1048576, "http2ConnectionWindowSize": 4194304, "http2FrameSize": 65536, "http2KeepaliveInterval": null, "http2KeepaliveTimeout": null } } } }
- Optional: Clean up and remove the AgentgatewayPolicy.
kubectl delete AgentgatewayPolicy http2-flow -n agentgateway-systemKeepalive
Manage idle and stale connections with HTTP/2 keepalive.