diff options
author | Roeland Jago Douma <roeland@famdouma.nl> | 2019-08-30 11:01:57 +0300 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-10-17 02:17:04 +0300 |
commit | 5f744699ca36aefa919668cb717ae15c045be89a (patch) | |
tree | 7a9864212574d12dfce761b267fad2abd3c125f5 /lib | |
parent | a2adb6aad7d798b192738ca0fa757f8aa3f406c4 (diff) |
Lets use the server methods for caching
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/AccountsController.php | 3 | ||||
-rw-r--r-- | lib/Controller/AliasesController.php | 2 | ||||
-rw-r--r-- | lib/Controller/AutoCompleteController.php | 2 | ||||
-rw-r--r-- | lib/Controller/AvatarsController.php | 16 | ||||
-rw-r--r-- | lib/Controller/FoldersController.php | 2 | ||||
-rw-r--r-- | lib/Controller/LocalAttachmentsController.php | 2 | ||||
-rwxr-xr-x | lib/Controller/MessagesController.php | 12 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 1 | ||||
-rw-r--r-- | lib/Controller/PreferencesController.php | 2 | ||||
-rw-r--r-- | lib/Http/AvatarDownloadResponse.php | 2 | ||||
-rw-r--r-- | lib/Http/CacheHeaders.php | 46 | ||||
-rw-r--r-- | lib/Http/HtmlResponse.php | 2 | ||||
-rw-r--r-- | lib/Http/JSONErrorResponse.php | 1 | ||||
-rw-r--r-- | lib/Http/JSONResponse.php | 35 | ||||
-rw-r--r-- | lib/Http/Middleware/ErrorMiddleware.php | 2 | ||||
-rw-r--r-- | lib/Http/ProxyDownloadResponse.php | 5 |
16 files changed, 17 insertions, 118 deletions
diff --git a/lib/Controller/AccountsController.php b/lib/Controller/AccountsController.php index 61fee9a7f..0198a34ba 100644 --- a/lib/Controller/AccountsController.php +++ b/lib/Controller/AccountsController.php @@ -30,11 +30,9 @@ declare(strict_types=1); namespace OCA\Mail\Controller; use Exception; -use Horde_Exception; use OCA\Mail\Contracts\IMailTransmission; use OCA\Mail\Exception\ClientException; use OCA\Mail\Exception\ServiceException; -use OCA\Mail\Http\JSONResponse; use OCA\Mail\Model\NewMessageData; use OCA\Mail\Model\RepliedMessageData; use OCA\Mail\Service\AccountService; @@ -43,6 +41,7 @@ use OCA\Mail\Service\GroupsIntegration; use OCA\Mail\Service\SetupService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; use OCP\IL10N; use OCP\ILogger; use OCP\IRequest; diff --git a/lib/Controller/AliasesController.php b/lib/Controller/AliasesController.php index 1d16f19de..cda86bd65 100644 --- a/lib/Controller/AliasesController.php +++ b/lib/Controller/AliasesController.php @@ -24,10 +24,10 @@ declare(strict_types=1); namespace OCA\Mail\Controller; use OCA\Mail\Exception\NotImplemented; -use OCA\Mail\Http\JSONResponse; use OCA\Mail\Service\AliasesService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; use OCP\IUser; use OCP\IUserSession; diff --git a/lib/Controller/AutoCompleteController.php b/lib/Controller/AutoCompleteController.php index a97340241..b714c5e1d 100644 --- a/lib/Controller/AutoCompleteController.php +++ b/lib/Controller/AutoCompleteController.php @@ -23,9 +23,9 @@ declare(strict_types=1); namespace OCA\Mail\Controller; -use OCA\Mail\Http\JSONResponse; use OCA\Mail\Service\AutoCompletion\AutoCompleteService; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; class AutoCompleteController extends Controller { diff --git a/lib/Controller/AvatarsController.php b/lib/Controller/AvatarsController.php index d7202dfda..7d5d26b7e 100644 --- a/lib/Controller/AvatarsController.php +++ b/lib/Controller/AvatarsController.php @@ -26,11 +26,10 @@ namespace OCA\Mail\Controller; use OCA\Mail\Contracts\IAvatarService; use OCA\Mail\Http\AvatarDownloadResponse; -use OCA\Mail\Http\JSONResponse; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; -use OCP\AppFramework\Utility\ITimeFactory; use OCP\IRequest; class AvatarsController extends Controller { @@ -41,19 +40,14 @@ class AvatarsController extends Controller { /** @var string */ private $uid; - /** @var ITimeFactory */ - private $timeFactory; - public function __construct(string $appName, IRequest $request, IAvatarService $avatarService, - string $UserId, - ITimeFactory $timeFactory) { + string $UserId) { parent::__construct($appName, $request); $this->avatarService = $avatarService; $this->uid = $UserId; - $this->timeFactory = $timeFactory; } /** @@ -80,7 +74,7 @@ class AvatarsController extends Controller { // Debounce this a bit // (cache for one day) - $response->setCacheHeaders(24 * 60 * 60, $this->timeFactory); + $response->cacheFor(24*60*60); return $response; } @@ -88,7 +82,7 @@ class AvatarsController extends Controller { $response = new JSONResponse($avatar); // Let the browser cache this for a week - $response->setCacheHeaders(7 * 24 * 60 * 60, $this->timeFactory); + $response->cacheFor(7 * 24 * 60 * 60); return $response; } @@ -118,7 +112,7 @@ class AvatarsController extends Controller { $resp->addHeader('Content-Type', $avatar->getMime()); // Let the browser cache this for a week - $resp->setCacheHeaders(7 * 24 * 60 * 60, $this->timeFactory); + $resp->cacheFor(7 * 24 * 60 * 60); return $resp; } diff --git a/lib/Controller/FoldersController.php b/lib/Controller/FoldersController.php index 6c5409df5..5316bfb1c 100644 --- a/lib/Controller/FoldersController.php +++ b/lib/Controller/FoldersController.php @@ -29,11 +29,11 @@ use function base64_decode; use function is_array; use OCA\Mail\Contracts\IMailManager; use OCA\Mail\Exception\NotImplemented; -use OCA\Mail\Http\JSONResponse; use OCA\Mail\IMAP\Sync\Request as SyncRequest; use OCA\Mail\Service\AccountService; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; class FoldersController extends Controller { diff --git a/lib/Controller/LocalAttachmentsController.php b/lib/Controller/LocalAttachmentsController.php index 5d6dfdd45..ce98814ba 100644 --- a/lib/Controller/LocalAttachmentsController.php +++ b/lib/Controller/LocalAttachmentsController.php @@ -26,10 +26,10 @@ namespace OCA\Mail\Controller; use OCA\Mail\Contracts\IAttachmentService; use OCA\Mail\Exception\ClientException; -use OCA\Mail\Http\JSONResponse; use OCA\Mail\Service\Attachment\UploadedFile; use OCP\AppFramework\Controller; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; class LocalAttachmentsController extends Controller { diff --git a/lib/Controller/MessagesController.php b/lib/Controller/MessagesController.php index a6d1821d7..32a87956a 100755 --- a/lib/Controller/MessagesController.php +++ b/lib/Controller/MessagesController.php @@ -85,9 +85,6 @@ class MessagesController extends Controller { /** @var IURLGenerator */ private $urlGenerator; - /** @var ITimeFactory */ - private $timeFactory; - /** * @param string $appName * @param IRequest $request @@ -98,7 +95,6 @@ class MessagesController extends Controller { * @param IL10N $l10n * @param IMimeTypeDetector $mimeTypeDetector * @param IURLGenerator $urlGenerator - * @param ITimeFactory $timeFactory */ public function __construct(string $appName, IRequest $request, @@ -110,8 +106,7 @@ class MessagesController extends Controller { ILogger $logger, IL10N $l10n, IMimeTypeDetector $mimeTypeDetector, - IURLGenerator $urlGenerator, - ITimeFactory $timeFactory) { + IURLGenerator $urlGenerator) { parent::__construct($appName, $request); $this->accountService = $accountService; @@ -123,7 +118,7 @@ class MessagesController extends Controller { $this->l10n = $l10n; $this->mimeTypeDetector = $mimeTypeDetector; $this->urlGenerator = $urlGenerator; - $this->timeFactory = $timeFactory; + $this->mailManager = $mailManager; } /** @@ -257,8 +252,7 @@ class MessagesController extends Controller { $htmlResponse->setContentSecurityPolicy($policy); // Enable caching - $htmlResponse->setCacheHeaders(60 * 60, $this->timeFactory); - $htmlResponse->addHeader('Pragma', 'cache'); + $htmlResponse->cacheFor(60 * 60); return $htmlResponse; } catch (Exception $ex) { diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index c74ce8c57..6538dd50a 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -28,7 +28,6 @@ namespace OCA\Mail\Controller; use Exception; use OCA\Mail\Contracts\IUserPreferences; -use OCA\Mail\Http\JSONResponse; use OCA\Mail\Service\AccountService; use OCA\Mail\Service\AliasesService; use OCA\Mail\Service\MailManager; diff --git a/lib/Controller/PreferencesController.php b/lib/Controller/PreferencesController.php index 1e00a118d..280f70422 100644 --- a/lib/Controller/PreferencesController.php +++ b/lib/Controller/PreferencesController.php @@ -28,8 +28,8 @@ namespace OCA\Mail\Controller; use OCA\Mail\Contracts\IUserPreferences; use OCA\Mail\Exception\ClientException; -use OCA\Mail\Http\JSONResponse; use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\JSONResponse; use OCP\IRequest; class PreferencesController extends Controller { diff --git a/lib/Http/AvatarDownloadResponse.php b/lib/Http/AvatarDownloadResponse.php index 0030e3d55..532c464c5 100644 --- a/lib/Http/AvatarDownloadResponse.php +++ b/lib/Http/AvatarDownloadResponse.php @@ -27,8 +27,6 @@ use OCP\AppFramework\Http\DownloadResponse; class AvatarDownloadResponse extends DownloadResponse { - use CacheHeaders; - /** @var string */ private $content; diff --git a/lib/Http/CacheHeaders.php b/lib/Http/CacheHeaders.php deleted file mode 100644 index c1ec0c999..000000000 --- a/lib/Http/CacheHeaders.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -declare(strict_types=1); - -/** - * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\Mail\Http; - -use DateInterval; -use DateTime; -use OCP\AppFramework\Utility\ITimeFactory; - -trait CacheHeaders { - - public function setCacheHeaders(int $cacheFor, ITimeFactory $timeFactory) { - $this->cacheFor($cacheFor); - - $expires = new DateTime(); - $expires->setTimestamp($timeFactory->getTime()); - $expires->add(new DateInterval('PT' . $cacheFor . 'S')); - $this->addHeader('Expires', $expires->format(DateTime::RFC1123)); - - $this->addHeader('Pragma', 'cache'); - } - -} diff --git a/lib/Http/HtmlResponse.php b/lib/Http/HtmlResponse.php index c50d251ca..37cd8b78d 100644 --- a/lib/Http/HtmlResponse.php +++ b/lib/Http/HtmlResponse.php @@ -29,8 +29,6 @@ use OCP\AppFramework\Http\Response; class HtmlResponse extends Response { - use CacheHeaders; - /** @var string */ private $content; diff --git a/lib/Http/JSONErrorResponse.php b/lib/Http/JSONErrorResponse.php index 69ff2aae7..4579f9bcb 100644 --- a/lib/Http/JSONErrorResponse.php +++ b/lib/Http/JSONErrorResponse.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace OCA\Mail\Http; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; class JSONErrorResponse extends JSONResponse { diff --git a/lib/Http/JSONResponse.php b/lib/Http/JSONResponse.php deleted file mode 100644 index 3ede7e46e..000000000 --- a/lib/Http/JSONResponse.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -declare(strict_types=1); - -/** - * @copyright 2017 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @author 2017 Christoph Wurst <christoph@winzerhof-wurst.at> - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\Mail\Http; - -use OCP\AppFramework\Http\JSONResponse as Base; - -class JSONResponse extends Base { - - use CacheHeaders; - -} diff --git a/lib/Http/Middleware/ErrorMiddleware.php b/lib/Http/Middleware/ErrorMiddleware.php index 9b5e60ab5..ab495804f 100644 --- a/lib/Http/Middleware/ErrorMiddleware.php +++ b/lib/Http/Middleware/ErrorMiddleware.php @@ -30,10 +30,10 @@ use Exception; use OCA\Mail\Exception\ClientException; use OCA\Mail\Exception\NotImplemented; use OCA\Mail\Http\JSONErrorResponse; -use OCA\Mail\Http\JSONResponse; use OCP\AppFramework\Controller; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\Response; use OCP\AppFramework\Middleware; use OCP\AppFramework\Utility\IControllerMethodReflector; diff --git a/lib/Http/ProxyDownloadResponse.php b/lib/Http/ProxyDownloadResponse.php index c8af04ee3..3fa4d3275 100644 --- a/lib/Http/ProxyDownloadResponse.php +++ b/lib/Http/ProxyDownloadResponse.php @@ -31,8 +31,6 @@ use OCP\AppFramework\Utility\ITimeFactory; class ProxyDownloadResponse extends DownloadResponse { - use CacheHeaders; - /** @var string */ private $content; @@ -51,10 +49,9 @@ class ProxyDownloadResponse extends DownloadResponse { $this->content = $content; - $time = OC::$server->query(ITimeFactory::class); $now = (new DateTime('now'))->getTimestamp(); $expires = (new DateTime('now + 11 months'))->getTimestamp(); - $this->setCacheHeaders($expires - $now, $time); + $this->cacheFor($expires - $now); } /** |