Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[RateLimiter] Document the RateLimit object#14461

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
javiereguiluz merged 1 commit intosymfony:5.xfromjaviereguiluz:fix_14447
Oct 22, 2020

Conversation

@javiereguiluz
Copy link
Member

Fixes#14447.

headers in the response to expose the limit status (e.g. remaining tokens, when
new tokens will be available, etc.)

That's why the ``consume()`` object returns a:class:`Symfony\\Component\\RateLimiter\\RateLimit`
Copy link
Member

Choose a reason for hiding this comment

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

Thereserve() method returns aReservation object that also has agetRateLimit() method.

javiereguiluz reacted with thumbs up emoji
Comment on lines 246 to 250
$response->headers->add([
'X-RateLimit-Remaining' => $limit->getRemainingTokens(),
'X-RateLimit-Reset' => $limit->getRetryAfter()->getTimestamp(),
'X-RateLimit-Limit' => $limit->getLimit(),
]);
Copy link
Member

Choose a reason for hiding this comment

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

These headers should be present in all responses, also the rejected ones. So what about changing this controller to:

$limiter =$anonymousApiLimiter->create($request->getClientIp());$rateLimit =$limiter->consume();$headers = ['X-RateLimit-Remaining' =>$limit->getRemainingTokens(),'X-RateLimit-Retry-After' =>$limit->getRetryAfter()->getTimestamp(),'X-RateLimit-Limit' =>$limit->getLimit(),];if (false ===$limit->isAccepted()) {returnnewResponse(null, Response::HTTP_TOO_MANY_REQUESTS,$headers);}// ...$response =newResponse(...);$response->headers->add($headers);return$response;

(btw, note that we should useX-RateLimit-Retry-After instead ofX-RateLimit-Reset)

javiereguiluz reacted with thumbs up emoji
@javiereguiluz
Copy link
MemberAuthor

Wouter, thanks for your review. These were fantastic fixes and suggestions, so I implemented all of them.

Copy link
Member

@wouterjwouterj left a comment

Choose a reason for hiding this comment

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

Thank you for taking care of documenting these changes Javier. Looks perfect to me this way!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@wouterjwouterjwouterj approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

5.2

Development

Successfully merging this pull request may close these issues.

[RateLimiter] rename Limit to RateLimit and add RateLimit::getLimit()

3 participants

@javiereguiluz@wouterj@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp