From f68481a357f5dac0a9870d472f8ed677c59dd8f9 Mon Sep 17 00:00:00 2001 From: Michael Flynn Date: Sun, 22 May 2022 21:31:24 -0400 Subject: [PATCH 1/2] Updating custom throttle reponse. Added the 2 parameters that the custom response callback is called with in the ThrottleRequests::buildException method. I tried to implement my own custom response and lost the throttle headers (X-RateLimit-Limit, etc). It was not obvious to me how to get the header info into my response. I tried to dig through the code, but missed the spot where the callback is called. Got a response to my problem on Laracasts, through I'd help put it in the docs for others. --- routing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routing.md b/routing.md index f3f65062200..6f295d66df6 100644 --- a/routing.md +++ b/routing.md @@ -661,8 +661,8 @@ Rate limiters are defined using the `RateLimiter` facade's `for` method. The `fo If the incoming request exceeds the specified rate limit, a response with a 429 HTTP status code will automatically be returned by Laravel. If you would like to define your own response that should be returned by a rate limit, you may use the `response` method: RateLimiter::for('global', function (Request $request) { - return Limit::perMinute(1000)->response(function () { - return response('Custom response...', 429); + return Limit::perMinute(1000)->response(function (Request $request, array $headers) { + return response('Custom response...', 429, $headers); }); }); From f002de7e3bb3bad860f9d1b025c51c5c67813b27 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 23 May 2022 10:42:58 -0500 Subject: [PATCH 2/2] Update routing.md --- routing.md | 1 + 1 file changed, 1 insertion(+) diff --git a/routing.md b/routing.md index 6f295d66df6..a86a72f9d3d 100644 --- a/routing.md +++ b/routing.md @@ -644,6 +644,7 @@ Laravel includes powerful and customizable rate limiting services that you may u Rate limiters are defined using the `RateLimiter` facade's `for` method. The `for` method accepts a rate limiter name and a closure that returns the limit configuration that should apply to routes that are assigned to the rate limiter. Limit configuration are instances of the `Illuminate\Cache\RateLimiting\Limit` class. This class contains helpful "builder" methods so that you can quickly define your limit. The rate limiter name may be any string you wish: use Illuminate\Cache\RateLimiting\Limit; + use Illuminate\Http\Request; use Illuminate\Support\Facades\RateLimiter; /**