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 {
$response = new TemplateResponse(
'core',
'429',
[],
'403',
[
'message' => $exception->getMessage(),
],
'guest'
);
$response->setStatus($exception->getCode());

View File

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

View File

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