Skip to content

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.

$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