How to apply different rate limits for different paths?
I want to apply a global throttle to all my API requests but for some paths apply a special rule. I could remove throttle middleware from Kernel.php and split all routes in groups but this would create a mess in routes file. Is there a way to keep a throttle middleware in Kernel.php applied to all routes and override its behavior for certain routes like this
Do you mean this:
'api' => [
'throttle:60,1',
'auth:api',
],
I think my solution in the past was to yank it out -- it's just a default Taylor wrote in so you don't have to. Then apply it in the api as needed.
Or maybe not, but I've coded different throttles and they worked fine.
I get what you are saying. The default throttle kicks in last and overwrites x-ratelimit-remaining. It calls $response->headers->add which replaces any other headers previously set.
An option is to override ThrottleRequests::addHeaders to use $response->headers->set($key, $values, FALSE); <-- default is true
This would keep the original x-ratelimit-remaining set.
For me ugly is the way to go. I like to explicitly set my middleware. Less secret sauce the better.