Implement ETag: header support for cache control

This commit is contained in:
Max Kostikov 2019-04-18 09:50:37 +02:00
parent 1732b2dfe3
commit 7a9093f634

View File

@ -40,7 +40,6 @@ class Photo extends \Zotlabs\Web\Controller {
call_hooks('cache_mode_hook', $cache_mode);
$observer_xchan = get_observer_hash();
$ismodified = $_SERVER['HTTP_IF_MODIFIED_SINCE'];
$cachecontrol = '';
if(isset($type)) {
@ -69,8 +68,6 @@ class Photo extends \Zotlabs\Web\Controller {
}
}
$modified = time();
$default = z_root() . '/' . $default;
$uid = $person;
$data = '';
@ -98,12 +95,12 @@ class Photo extends \Zotlabs\Web\Controller {
$default = $d['default'];
$data = $d['data'];
$mimetype = $d['mimetype'];
$modified = time();
}
if(! $data) {
$x = z_fetch_url($default,true,0,[ 'novalidate' => true ]);
$data = ($x['success'] ? $x['body'] : EMPTY_STR);
$mimetype = 'image/png';
header("Location: " . z_root() . '/' . $default);
killme();
}
$cachecontrol = ', must-revalidate';
@ -212,6 +209,7 @@ class Photo extends \Zotlabs\Web\Controller {
if(! $exists) {
http_status_exit(404,'not found');
}
}
}
else
@ -223,7 +221,7 @@ class Photo extends \Zotlabs\Web\Controller {
header_remove('Pragma');
if($ismodified === gmdate("D, d M Y H:i:s", $modified) . " GMT") {
if($_SERVER['HTTP_IF_NONE_MATCH'] == md5($data) || $_SERVER['HTTP_IF_MODIFIED_SINCE'] === gmdate("D, d M Y H:i:s", $modified) . " GMT") {
header_remove('Expires');
header_remove('Cache-Control');
header_remove('Set-Cookie');
@ -272,6 +270,7 @@ class Photo extends \Zotlabs\Web\Controller {
header("Content-type: " . $mimetype);
header("Last-Modified: " . gmdate("D, d M Y H:i:s", $modified) . " GMT");
header("ETag: " . md5($data));
header("Content-Length: " . (isset($filesize) ? $filesize : strlen($data)));
// If it's a file resource, stream it.