-
Notifications
You must be signed in to change notification settings - Fork 76
Add custom period of blocking time #70
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
base: main
Are you sure you want to change the base?
Conversation
We added the package for more convenient development. It allows an IDE make auto complete.
We will check this field and will discard requests if it is set up blocked.
We added the key for more convenient handling of RateLimitInfo in service storages.
We added that ability, because sometimes we want to use another period of time for blocking a specific call, but we want to save a period of time when somebody can do requests of URLs without restrictions.
We need this event for making different things when a block happens.
We should dispatch that event, because some developers want to do additional things when block happens. For example, to register block event into system log.
We added dispatching the event before sending a response. It needs when we want to send another more reach message in the response. Also it allows us to make other types of responses.
This feature allows to block the URL or call for custom period of time which can be not equal period or might be omit at all.
This looks like a great feature, if the conflicts could be resolved I'd like to merge it. |
*/ | ||
public function setKey($key) | ||
{ | ||
$this->key = (string)$key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why you want to set the key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the key there.
# Service/Storage/StorageInterface.php
/**
* Set block for the call
*
* @param RateLimitInfo $rateLimitInfo
* @param integer $periodBlock
*
* @return bool
*/
public function setBlock(RateLimitInfo $rateLimitInfo, $periodBlock);
If we passed only the key
and periodBlock
into setBlock
method we would have to load cache data before setting block in some storages. It's not a good idea to load data if we have already them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better for this to work like the other functions in RateLimitService and have $key as the first parameter
# Conflicts: # Service/Storage/DoctrineCache.php # Service/Storage/Memcache.php # composer.json # composer.lock
@mcfedr we fixed all the conflicts. |
if (!$rateLimitInfo->isBlocked() && $rateLimitInfo->getCalls() > $rateLimitInfo->getLimit()) { | ||
$this->rateLimitService->setBlock( | ||
$rateLimitInfo, | ||
$rateLimit->getBlockPeriod() > 0 ? $rateLimit->getBlockPeriod() : $rateLimit->getPeriod() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think If the block period isn't set, there should be no extended block period, as in how system works at the moment.
*/ | ||
public function setKey($key) | ||
{ | ||
$this->key = (string)$key; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better for this to work like the other functions in RateLimitService and have $key as the first parameter
$info['limit'] = $limit; | ||
$info['calls'] = 1; | ||
$info['reset'] = time() + $period; | ||
$info['blocked'] = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocked is a bool, no need to mix it with ints
This changes allow developers to set custom period of blocking time of a call through either an annotation or YAML.