class ThrottleRequests

Properties

protected RateLimiter $limiter

The rate limiter instance.

Methods

void
__construct(RateLimiter $limiter)

Create a new request throttler.

mixed
handle(Request $request, Closure $next, int $maxAttempts = 60, float|int $decayMinutes = 1)

Handle an incoming request.

string
resolveRequestSignature(Request $request)

Resolve request signature.

Response
buildResponse(string $key, int $maxAttempts)

Create a 'too many attempts' response.

Response
addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)

Add the limit header information to the given response.

int
calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null)

Calculate the number of remaining attempts.

Details

at line 25
void __construct(RateLimiter $limiter)

Create a new request throttler.

Parameters

RateLimiter $limiter

Return Value

void

at line 39
mixed handle(Request $request, Closure $next, int $maxAttempts = 60, float|int $decayMinutes = 1)

Handle an incoming request.

Parameters

Request $request
Closure $next
int $maxAttempts
float|int $decayMinutes

Return Value

mixed

at line 63
protected string resolveRequestSignature(Request $request)

Resolve request signature.

Parameters

Request $request

Return Value

string

at line 75
protected Response buildResponse(string $key, int $maxAttempts)

Create a 'too many attempts' response.

Parameters

string $key
int $maxAttempts

Return Value

Response

at line 97
protected Response addHeaders(Response $response, int $maxAttempts, int $remainingAttempts, int|null $retryAfter = null)

Add the limit header information to the given response.

Parameters

Response $response
int $maxAttempts
int $remainingAttempts
int|null $retryAfter

Return Value

Response

at line 122
protected int calculateRemainingAttempts(string $key, int $maxAttempts, int|null $retryAfter = null)

Calculate the number of remaining attempts.

Parameters

string $key
int $maxAttempts
int|null $retryAfter

Return Value

int