429 template is NC20+ and fix getDelay for CLI

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2021-04-29 08:44:53 +02:00
parent f585fbc391
commit 43d6921772
No known key found for this signature in database
GPG Key ID: 7076EA9751AACDDA
3 changed files with 12 additions and 4 deletions

View File

@ -114,8 +114,10 @@ class RateLimitingMiddleware extends Middleware {
} else { } else {
$response = new TemplateResponse( $response = new TemplateResponse(
'core', 'core',
'429', '403',
[], [
'message' => $exception->getMessage(),
],
'guest' 'guest'
); );
$response->setStatus($exception->getCode()); $response->setStatus($exception->getCode());

View File

@ -212,6 +212,10 @@ class Throttler {
return 0; return 0;
} }
if ($ip === '') {
return 0;
}
$cutoffTime = (new \DateTime()) $cutoffTime = (new \DateTime())
->sub($this->getCutoff(43200)) ->sub($this->getCutoff(43200))
->getTimestamp(); ->getTimestamp();

View File

@ -270,8 +270,10 @@ class RateLimitingMiddlewareTest extends TestCase {
$result = $this->rateLimitingMiddleware->afterException($controller, 'testMethod', new RateLimitExceededException()); $result = $this->rateLimitingMiddleware->afterException($controller, 'testMethod', new RateLimitExceededException());
$expected = new TemplateResponse( $expected = new TemplateResponse(
'core', 'core',
'429', '403',
[], [
'message' => 'Rate limit exceeded',
],
'guest' 'guest'
); );
$expected->setStatus(429); $expected->setStatus(429);