mirror of
https://github.com/maelgangloff/domain-watchdog.git
synced 2025-12-29 16:15:04 +00:00
fix: correct rate limiter
This commit is contained in:
@@ -14,7 +14,6 @@ use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
|
|||||||
use Symfony\Component\HttpKernel\KernelInterface;
|
use Symfony\Component\HttpKernel\KernelInterface;
|
||||||
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
use Symfony\Component\Messenger\Exception\ExceptionInterface;
|
||||||
use Symfony\Component\Messenger\MessageBusInterface;
|
use Symfony\Component\Messenger\MessageBusInterface;
|
||||||
use Symfony\Component\RateLimiter\Exception\RateLimitExceededException;
|
|
||||||
use Symfony\Component\RateLimiter\RateLimiterFactory;
|
use Symfony\Component\RateLimiter\RateLimiterFactory;
|
||||||
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\DecodingExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||||
@@ -65,10 +64,10 @@ class DomainRefreshController extends AbstractController
|
|||||||
|
|
||||||
if (false === $kernel->isDebug() && true === $this->getParameter('limited_features')) {
|
if (false === $kernel->isDebug() && true === $this->getParameter('limited_features')) {
|
||||||
$limiter = $this->rdapRequestsLimiter->create($userId);
|
$limiter = $this->rdapRequestsLimiter->create($userId);
|
||||||
try {
|
$limit = $limiter->consume();
|
||||||
$limiter->consume()->ensureAccepted();
|
|
||||||
} catch (RateLimitExceededException $e) {
|
if (!$limit->isAccepted()) {
|
||||||
throw new TooManyRequestsHttpException($e->getRetryAfter()->getTimestamp() - time(), $e->getMessage());
|
throw new TooManyRequestsHttpException($limit->getRetryAfter()->getTimestamp() - time());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ use Symfony\Component\HttpKernel\KernelInterface;
|
|||||||
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Component\Mime\Address;
|
use Symfony\Component\Mime\Address;
|
||||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
||||||
use Symfony\Component\RateLimiter\Exception\RateLimitExceededException;
|
|
||||||
use Symfony\Component\RateLimiter\RateLimiterFactory;
|
use Symfony\Component\RateLimiter\RateLimiterFactory;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
@@ -57,11 +56,10 @@ class RegistrationController extends AbstractController
|
|||||||
|
|
||||||
if (false === $this->kernel->isDebug()) {
|
if (false === $this->kernel->isDebug()) {
|
||||||
$limiter = $this->userRegisterLimiter->create($request->getClientIp());
|
$limiter = $this->userRegisterLimiter->create($request->getClientIp());
|
||||||
|
$limit = $limiter->consume();
|
||||||
|
|
||||||
try {
|
if (!$limit->isAccepted()) {
|
||||||
$limiter->consume()->ensureAccepted();
|
throw new TooManyRequestsHttpException($limit->getRetryAfter()->getTimestamp() - time());
|
||||||
} catch (RateLimitExceededException $e) {
|
|
||||||
throw new TooManyRequestsHttpException($e->getRetryAfter()->getTimestamp() - time(), $e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user