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-18 00:33:39 +0400
committerBart Visscher <bartv@thisnet.nl>2012-02-18 01:07:13 +0400
commitbcbebe390b2689de34f60d124d19c9154d531f5e (patch)
tree62629ecafe2a2a04781e3b0df4f6fe228c67864f /lib/response.php
parent86893ea78c6227187ac7a5de20fca7e711968447 (diff)
Document OC_Response
Diffstat (limited to 'lib/response.php')
-rw-r--r--lib/response.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/response.php b/lib/response.php
index 2fa0a5adcd3..3765f509c18 100644
--- a/lib/response.php
+++ b/lib/response.php
@@ -12,6 +12,13 @@ class OC_Response {
const STATUS_TEMPORARY_REDIRECT = 307;
const STATUS_NOT_FOUND = 404;
+ /**
+ * @brief Enable response caching by sending correct HTTP headers
+ * @param $cache_time time to cache the response
+ * >0 cache time in seconds
+ * 0 and <0 enable default browser caching
+ * null cache indefinitly
+ */
static public function enableCaching($cache_time = null) {
if (is_numeric($cache_time)) {
header('Pragma: public');// enable caching in IE
@@ -30,10 +37,19 @@ class OC_Response {
}
}
+
+ /**
+ * @brief disable browser caching
+ * @see enableCaching with cache_time = 0
+ */
static public function disableCaching() {
self::enableCaching(0);
}
+ /**
+ * @brief Set response status
+ * @param $status a HTTP status code, see also the STATUS constants
+ */
static public function setStatus($status) {
$protocol = $_SERVER['SERVER_PROTOCOL'];
switch($status) {
@@ -58,11 +74,21 @@ class OC_Response {
header($protocol.' '.$status);
}
+ /**
+ * @brief Send redirect response
+ * @param $location to redirect to
+ */
static public function redirect($location) {
self::setStatus(self::STATUS_TEMPORARY_REDIRECT);
header('Location: '.$location);
}
+ /**
+ * @brief Set reponse expire time
+ * @param $expires date-time when the response expires
+ * string for DateInterval from now
+ * DateTime object when to expire response
+ */
static public function setExpiresHeader($expires) {
if (is_string($expires) && $expires[0] == 'P') {
$interval = $expires;
@@ -76,6 +102,11 @@ class OC_Response {
header('Expires: '.$expires);
}
+ /**
+ * Checks and set ETag header, when the request matches sends a
+ * 'not modified' response
+ * @param $etag token to use for modification check
+ */
static public function setETagHeader($etag) {
if (empty($etag)) {
return;
@@ -88,6 +119,11 @@ class OC_Response {
header('ETag: '.$etag);
}
+ /**
+ * Checks and set Last-Modified header, when the request matches sends a
+ * 'not modified' response
+ * @param $lastModified time when the reponse was last modified
+ */
static public function setLastModifiedHeader($lastModified) {
if (empty($lastModified)) {
return;
@@ -106,6 +142,10 @@ class OC_Response {
header('Last-Modified: '.$lastModified);
}
+ /**
+ * @brief Send file as response, checking and setting caching headers
+ * @param $filepath of file to send
+ */
static public function sendFile($filepath=null) {
$fp = fopen($filepath, 'rb');
if ($fp) {