Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-02-12 20:20:30 +0400
committerBart Visscher <bartv@thisnet.nl>2012-02-12 20:21:33 +0400
commit0917bdecddd74a48ee2b21f18e184c579d156b62 (patch)
tree440ef374bcecc71752ecd3fa725165c9a8b94989 /lib/response.php
parenta0bb6079c5169f7314b9c82983e7a019469c2a00 (diff)
Contacts: Move response caching to OC_Response
Diffstat (limited to 'lib/response.php')
-rw-r--r--lib/response.php54
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);
+ }
+}