Skip to content
Snippets Groups Projects
Commit 45bb6f5f authored by Bart Visscher's avatar Bart Visscher
Browse files

OC_Response: add redirect function

parent ee7931f4
No related branches found
No related tags found
No related merge requests found
...@@ -30,10 +30,8 @@ function getStandardImage(){ ...@@ -30,10 +30,8 @@ function getStandardImage(){
$date = new DateTime('now'); $date = new DateTime('now');
$date->add(new DateInterval('P10D')); $date->add(new DateInterval('P10D'));
header('Expires: '.$date->format(DateTime::RFC2822)); header('Expires: '.$date->format(DateTime::RFC2822));
header('Cache-Control: cache'); OC_Response::enableCaching();
header('Pragma: cache'); OC_Response::redirect(OC_Helper::imagePath('contacts', 'person.png'));
header("HTTP/1.1 307 Temporary Redirect");
header('Location: '.OC_Helper::imagePath('contacts', 'person.png'));
} }
if(!function_exists('imagecreatefromjpeg')) { if(!function_exists('imagecreatefromjpeg')) {
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
*/ */
class OC_Response { class OC_Response {
const STATUS_FOUND = 304;
const STATUS_NOT_MODIFIED = 304; const STATUS_NOT_MODIFIED = 304;
const STATUS_TEMPORARY_REDIRECT = 307;
static public function enableCaching() { static public function enableCaching() {
header('Cache-Control: cache'); header('Cache-Control: cache');
...@@ -15,12 +17,29 @@ class OC_Response { ...@@ -15,12 +17,29 @@ class OC_Response {
} }
static public function setStatus($status) { static public function setStatus($status) {
$protocol = $_SERVER['SERVER_PROTOCOL'];
switch($status) { switch($status) {
case self::STATUS_NOT_MODIFIED: case self::STATUS_NOT_MODIFIED:
$status = $status . ' Not Modified'; $status = $status . ' Not Modified';
break; break;
case self::STATUS_TEMPORARY_REDIRECT:
if ($protocol == 'HTTP/1.1') {
$status = $status . ' Temporary Redirect';
break;
} else {
$status = self::STATUS_FOUND;
// fallthrough
}
case self::STATUS_FOUND;
$status = $status . ' Found';
break;
} }
header($_SERVER["SERVER_PROTOCOL"].' '.$status); header($protocol.' '.$status);
}
static public function redirect($location) {
self::setStatus(self::STATUS_TEMPORARY_REDIRECT);
header('Location: '.$location);
} }
static public function setETagHeader($etag) { static public function setETagHeader($etag) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment