2020-03-19 12:09:57 +01:00
|
|
|
<?php
|
2020-07-09 12:25:57 +02:00
|
|
|
|
2020-03-19 12:09:57 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
2024-05-23 09:26:56 +02:00
|
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-03-19 12:09:57 +01:00
|
|
|
*/
|
|
|
|
namespace OCP\AppFramework\Http;
|
|
|
|
|
2023-06-14 08:56:42 +02:00
|
|
|
use OCP\AppFramework\Http;
|
2025-02-27 11:05:44 +01:00
|
|
|
use OCP\Server;
|
|
|
|
use OCP\Template\ITemplateManager;
|
2020-03-19 12:09:57 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A generic 429 response showing an 404 error page as well to the end-user
|
|
|
|
* @since 19.0.0
|
2024-12-16 16:20:48 +01:00
|
|
|
* @template S of Http::STATUS_*
|
2023-06-14 08:56:42 +02:00
|
|
|
* @template H of array<string, mixed>
|
2024-12-16 16:20:48 +01:00
|
|
|
* @template-extends Response<Http::STATUS_*, array<string, mixed>>
|
2020-03-19 12:09:57 +01:00
|
|
|
*/
|
|
|
|
class TooManyRequestsResponse extends Response {
|
|
|
|
/**
|
2023-06-14 08:56:42 +02:00
|
|
|
* @param S $status
|
|
|
|
* @param H $headers
|
2020-03-19 12:09:57 +01:00
|
|
|
* @since 19.0.0
|
|
|
|
*/
|
2023-06-14 08:56:42 +02:00
|
|
|
public function __construct(int $status = Http::STATUS_TOO_MANY_REQUESTS, array $headers = []) {
|
|
|
|
parent::__construct($status, $headers);
|
2020-03-19 12:09:57 +01:00
|
|
|
|
|
|
|
$this->setContentSecurityPolicy(new ContentSecurityPolicy());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
* @since 19.0.0
|
|
|
|
*/
|
|
|
|
public function render() {
|
2025-02-27 11:05:44 +01:00
|
|
|
$template = Server::get(ITemplateManager::class)->getTemplate('core', '429', TemplateResponse::RENDER_AS_BLANK);
|
2020-03-19 12:09:57 +01:00
|
|
|
return $template->fetchPage();
|
|
|
|
}
|
|
|
|
}
|