Skip to main content

client-control

Controls the client request body size.

Category TrafficAdd it to Route, Service, Consumer, Consumer group, Global rule, Plugin configEngine plugin client-controlPriority 22000

What 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 POST with a short body is answered 200, and one with a body of thirty-two characters is answered 413.
  • 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 limitmax_body_sizeinteger

The largest request body accepted, in bytes, such as 1048576 for 1 MiB. Zero lifts the limit.

at least 0

Every plugin also has Enabled, Priority, Filter, Error response and Pre-function: see Plugin execution settings.

G8 dev · Apache APISIX® 3.19.0
Apache, Apache APISIX and APISIX are trademarks of The Apache Software Foundation.
Facts
Category
Traffic
Add it to
Route, Service, Consumer, Consumer group, Global rule, Plugin config
Engine plugin
client-control
Priority
22000