Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[RateLimiter] Return getRetryAfter() method usage #19205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 0 commits into from

Conversation

ERuban
Copy link

@ERuban ERuban commented Nov 30, 2023

We cannot use RateLimit->calculateTimeForTokens(1, 1) there, bcs it is from SlidingWindow class

Copy link
Member

@wouterj wouterj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're 100% correct that we shouldn't use this (internal) method as public API.

rate_limiter.rst Outdated
@@ -353,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->calculateTimeForTokens(1, 1),
'X-RateLimit-Retry-After' => $limit->getRetryAfter()->getTimestamp(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header must contain the number of seconds from now to retry I believe. So we can do something like:

Suggested change
'X-RateLimit-Retry-After' => $limit->getRetryAfter()->getTimestamp(),
'X-RateLimit-Retry-After' => now() - $limit->getRetryAfter()->getTimestamp(),

And then add use function Symfony\Component\Clock\now; at the top of the example.

@OskarStark OskarStark modified the milestones: 6.4, 5.4 Dec 9, 2023
@OskarStark
Copy link
Contributor

OskarStark commented Dec 9, 2023

I will take of the comments while merging, using time() over now() for now and switch

- 'X-RateLimit-Retry-After' => now() - $limit->getRetryAfter()->getTimestamp(),
+ 'X-RateLimit-Retry-After' => $limit->getRetryAfter()->getTimestamp() - time(),

@OskarStark OskarStark changed the base branch from 6.4 to 5.4 December 9, 2023 09:37
@OskarStark OskarStark requested a review from xabbuh as a code owner December 9, 2023 09:37
@OskarStark OskarStark closed this Dec 9, 2023
@OskarStark OskarStark force-pushed the fix_rate_limiter_page branch from 4731402 to c61dc1f Compare December 9, 2023 09:37
@OskarStark
Copy link
Contributor

I am very sorry @ERuban I am not sure what happened, but my an error happened while merging your PR, I applied the change myself in e1e9205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.