diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-02-12 17:20:30 +0100 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-02-12 17:21:33 +0100 |
commit | 0917bdecddd74a48ee2b21f18e184c579d156b62 (patch) | |
tree | 440ef374bcecc71752ecd3fa725165c9a8b94989 /lib/response.php | |
parent | a0bb6079c5169f7314b9c82983e7a019469c2a00 (diff) | |
download | nextcloud-server-0917bdecddd74a48ee2b21f18e184c579d156b62.tar.gz nextcloud-server-0917bdecddd74a48ee2b21f18e184c579d156b62.zip |
Contacts: Move response caching to OC_Response
Diffstat (limited to 'lib/response.php')
-rw-r--r-- | lib/response.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/response.php b/lib/response.php new file mode 100644 index 00000000000..c254ddd10e7 --- /dev/null +++ b/lib/response.php @@ -0,0 +1,54 @@ +<?php +/** + * Copyright (c) 2011 Bart Visscher bartv@thisnet.nl + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +class OC_Response { + const STATUS_NOT_MODIFIED = 304; + + static public function enableCaching() { + header('Cache-Control: cache'); + header('Pragma: cache'); + } + + static public function setStatus($status) { + switch($status) { + case self::STATUS_NOT_MODIFIED: + $status = $status . ' Not Modified'; + break; + } + header($_SERVER["SERVER_PROTOCOL"].' '.$status); + } + + static public function setETagHeader($etag) { + if (empty($etag)) { + return; + } + self::enableCaching(); + if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && + trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { + self::setStatus(self::STATUS_NOT_MODIFIED); + exit; + } + header('ETag: '.$etag); + } + + static public function setLastModifiedHeader($lastModified) { + if (empty($lastModified)) { + return; + } + if ($lastModified instanceof DateTime) { + $lastModified = $lastModified->format(DateTime::RFC2822); + } + self::enableCaching(); + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && + trim($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified) { + self::setStatus(self::STATUS_NOT_MODIFIED); + exit; + } + header('Last-Modified: '.$lastModified); + } +} |