Skip to main content

client-control

The client-control plugin sets a request body size limit on a route or service. It lets individual APIs enforce a limit that differs from the gateway-wide NGINX configuration and rejects oversized requests before they reach the upstream service.

Request Handling and Product Compatibility​

When a request declares Content-Length, the plugin rejects it immediately with 413 Request Entity Too Large if the declared size exceeds a nonzero configured limit. For a request without a known length, the gateway continues enforcing the limit while NGINX reads the body.

The plugin is available in APISIX and API7 Enterprise. Its behavior for gRPC upstreams differs in the currently maintained versions:

ProductHTTP requestsRequests to gRPC upstreams
APISIX 3.19.0Enforces the configured limit.Performs the initial declared-length check but does not reapply the runtime limit after the internal redirect. Do not rely on this plugin as the gRPC body-size control in this version.
APISIX 3.20.0Enforces the configured limit.Reapplies the limit after the internal gRPC redirect, including when the request does not declare Content-Length.
API7 Enterprise 3.9.23 and 3.10.10Enforces the configured limit.Performs the initial declared-length check but does not reapply the runtime limit after the internal redirect. Do not rely on this plugin as the gRPC body-size control in these versions.

Example​

Set a 1 KiB limit on a route, then send requests below and above the limit to verify that the gateway rejects oversized bodies.

Limit Request Body Size​

Create a route with the client-control plugin:

curl "http://127.0.0.1:9180/apisix/admin/routes" -X PUT \
-H "X-API-KEY: ${ADMIN_API_KEY}" \
-d '{
"id": "client-control-route",
"uri": "/anything",
"plugins": {
"client-control": {
"max_body_size": 1024
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org:80": 1
}
}
}'

Send a small request that stays within the limit:

curl -i "http://127.0.0.1:9080/anything" \
-H "Content-Type: application/json" \
-d '{"message":"ok"}'

The request should reach the upstream and return an HTTP 2xx response.

Send a 2 KiB request body:

head -c 2048 /dev/zero | \
curl -i "http://127.0.0.1:9080/anything" \
-H "Content-Type: application/octet-stream" \
--data-binary @-

The gateway should reject the request with 413 Request Entity Too Large.