Added If-Modified-Since
header support for better image caching and fixed absent 404 for photos
This commit is contained in:
parent
fc1d8c0138
commit
eaf117cce1
@ -10,7 +10,7 @@ require_once('include/photos.php');
|
|||||||
class Photo extends \Zotlabs\Web\Controller {
|
class Photo extends \Zotlabs\Web\Controller {
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
|
|
||||||
$prvcachecontrol = false;
|
$prvcachecontrol = false;
|
||||||
$streaming = null;
|
$streaming = null;
|
||||||
$channel = null;
|
$channel = null;
|
||||||
@ -32,6 +32,7 @@ class Photo extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$observer_xchan = get_observer_hash();
|
$observer_xchan = get_observer_hash();
|
||||||
|
$ismodified = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
|
||||||
|
|
||||||
if(isset($type)) {
|
if(isset($type)) {
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ class Photo extends \Zotlabs\Web\Controller {
|
|||||||
if(intval($r[0]['os_storage']))
|
if(intval($r[0]['os_storage']))
|
||||||
$data = file_get_contents($data);
|
$data = file_get_contents($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(! $data) {
|
if(! $data) {
|
||||||
$data = fetch_image_from_url($default,$mimetype);
|
$data = fetch_image_from_url($default,$mimetype);
|
||||||
}
|
}
|
||||||
@ -179,8 +181,19 @@ class Photo extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
http_status_exit(404,'not found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header_remove('Pragma');
|
||||||
|
|
||||||
|
if($ismodified === gmdate("D, d M Y H:i:s", $modified) . " GMT") {
|
||||||
|
header_remove('Expires');
|
||||||
|
header_remove('Cache-Control');
|
||||||
|
header_remove('Set-Cookie');
|
||||||
|
http_status_exit(304,'not modified');
|
||||||
|
}
|
||||||
|
|
||||||
if(! isset($data)) {
|
if(! isset($data)) {
|
||||||
if(isset($resolution)) {
|
if(isset($resolution)) {
|
||||||
@ -219,11 +232,6 @@ class Photo extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(function_exists('header_remove')) {
|
|
||||||
header_remove('Pragma');
|
|
||||||
header_remove('pragma');
|
|
||||||
}
|
|
||||||
|
|
||||||
header("Content-type: " . $mimetype);
|
header("Content-type: " . $mimetype);
|
||||||
|
|
||||||
if($prvcachecontrol) {
|
if($prvcachecontrol) {
|
||||||
|
Reference in New Issue
Block a user