From b5b00937f16fa95e9abc58d643a55696789a286d Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Mon, 2 Oct 2023 10:06:00 +0200 Subject: [PATCH] [RateLimiter] Add `SlidingWindowLimiter::reserve()` --- rate_limiter.rst | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/rate_limiter.rst b/rate_limiter.rst index 981167095d2..06c888b480b 100644 --- a/rate_limiter.rst +++ b/rate_limiter.rst @@ -320,6 +320,11 @@ processes by reserving unused tokens. $limit->wait(); } while (!$limit->isAccepted()); +.. versionadded:: 6.4 + + The support for the ``reserve()`` method for the ``SlidingWindow`` strategy + was introduced in Symfony 6.4. + Exposing the Rate Limiter Status ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -348,7 +353,7 @@ the :class:`Symfony\\Component\\RateLimiter\\Reservation` object returned by the $limit = $limiter->consume(); $headers = [ 'X-RateLimit-Remaining' => $limit->getRemainingTokens(), - 'X-RateLimit-Retry-After' => $limit->getRetryAfter()->getTimestamp(), + 'X-RateLimit-Retry-After' => $limit->calculateTimeForTokens(1, 1), 'X-RateLimit-Limit' => $limit->getLimit(), ]; @@ -365,6 +370,19 @@ the :class:`Symfony\\Component\\RateLimiter\\Reservation` object returned by the } } +.. versionadded:: 6.4 + + The :method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::calculateTimeForTokens` + method was introduced in Symfony 6.4. + +.. deprecated:: 6.4 + + The :method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::getRetryAfter` + method is deprecated since Symfony 6.4. Prior to this version, the + ``getRetryAfter()`` method must be used instead of the + :method:`Symfony\\Component\\RateLimiter\\Policy\\SlidingWindow::calculateTimeForTokens` + method. + .. _rate-limiter-storage: Storing Rate Limiter State