I'd like to set rateLimit for requests where in json data present param with sample value
Example
curl -X 'POST' 'http://127.0.0.1/' -H Host:whoami.docker.localhost -H 'accept: application/json' -H 'Content-Type: application/json' -d '{
"sender": "Tester",
"receiver": [
"receiver1"
],
"text": "Text",
"service": "service"
}'
I need limit 100rps for sender=Tester, other senders must have no rateLimit
I tried such config:
[http.routers]
[http.routers.whoami_1]
rule = "Host(`whoami.docker.localhost`)&&Query(sender=Tester)"
service = "whoami"
entrypoints = ["web"]
middlewares = ["test-ratelimit"]
[http.middlewares]
[http.middlewares.test-ratelimit.rateLimit]
average = 100
But received
404 page not found
How can I get param from json data in request and set rule for routes or middleware?
CodePudding user response:
Traefik does not provide middlewares to extract the JSON payload from the request.
You can probably try to create a custom plugin extracting the value and applying the rate limiting on its own.