client-control
Controls the client request body size.
Category TrafficAdd it to Route, Service, Consumer, Consumer group, Global rule, Plugin configEngine plugin
client-controlPriority 22000What it does
client-control refuses a request on a route whose body is larger than Body size limit. The limit is written in bytes, so 10 megabytes is 10485760.
A request over the limit is answered 413, an answer the gateway gives itself, as How G8 handles a request describes. A request within it goes on to the backend as before.
When to use it
- An upload route of the orders API that takes attachments up to 10 megabytes and refuses larger ones at the gateway.
- A JSON API whose requests are small, where a large body is a mistake or an attempt to tie up the backend.
- Different limits per route: a small one on most routes and a larger one on the route that takes files.
Not for limiting how many requests a client sends — see limit-count (Limits the number of requests in a time window, per key).
Set it up
Refuse request bodies larger than 10 megabytes on this route
A larger body is answered 413 before it is read.
Set Body size limit to 10485760.
client-control · as the console saves it
{
"max_body_size": 10485760
}
Things to know
- Body size limit — Run with a limit of 16 bytes, a
POSTwith a short body is answered200, and one with a body of thirty-two characters is answered413. - Body size limit — Nothing else on the gateway limits request bodies, so without this plugin any size is taken. Over the limit the answer is 413.
- Body size limit — The limit is a whole number of bytes. A fraction, for example
1.5, is refused when you save. - AdviceSet each route's limit to the largest body its clients send, and keep a larger limit on the few routes that take files.
Settings
The fields as the console shows them, section by section.
Body size limit
max_body_sizeintegerThe largest request body accepted, in bytes, such as 1048576 for 1 MiB. Zero lifts the limit.
at least 0
G8 dev · Apache APISIX® 3.19.0
Apache, Apache APISIX and APISIX are trademarks of The Apache Software Foundation.