client-control

Description

The client-control Plugin can be used to dynamically control the behavior of NGINX to handle a client request, by setting the max size of the request body.

client-control - 图1IMPORTANT

This Plugin requires APISIX to run on APISIX-Base. See apisix-build-tools for more info.

Attributes

NameTypeRequiredValid valuesDescription
max_body_sizeintegerFalse[0,…]Dynamically set the client_max_body_size directive.

Enabling the Plugin

The example below enables the Plugin on a specific Route:

  1. curl -i http://127.0.0.1:9180/apisix/admin/routes/1 \
  2. -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  3. {
  4. "uri": "/index.html",
  5. "plugins": {
  6. "client-control": {
  7. "max_body_size" : 1
  8. }
  9. },
  10. "upstream": {
  11. "type": "roundrobin",
  12. "nodes": {
  13. "127.0.0.1:1980": 1
  14. }
  15. }
  16. }'

Example usage

Now since you have configured the max_body_size to 1 above, you will get the following message when you make a request:

  1. curl -i http://127.0.0.1:9080/index.html -d '123'
  1. HTTP/1.1 413 Request Entity Too Large
  2. ...
  3. <html>
  4. <head><title>413 Request Entity Too Large</title></head>
  5. <body>
  6. <center><h1>413 Request Entity Too Large</h1></center>
  7. <hr><center>openresty</center>
  8. </body>
  9. </html>

Disable Plugin

To disable the client-control Plugin, you can delete the corresponding JSON configuration from the Plugin configuration. APISIX will automatically reload, and you do not have to restart for this to take effect.

  1. curl http://127.0.0.1:9180/apisix/admin/routes/1 \
  2. -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
  3. {
  4. "uri": "/index.html",
  5. "upstream": {
  6. "type": "roundrobin",
  7. "nodes": {
  8. "127.0.0.1:1980": 1
  9. }
  10. }
  11. }'