From a62f891a60fff0fd7e0a3f625524ed3277290e58 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 17 Apr 2019 18:30:50 +0200 Subject: Precise 'Modified:' header processing if no profile photo added; remove duplicated code --- Zotlabs/Module/Photo.php | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 37ae03460..37dfa03e4 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -68,7 +68,7 @@ class Photo extends \Zotlabs\Web\Controller { } } - $modified = filemtime($default); + $modified = time(); $default = z_root() . '/' . $default; $uid = $person; @@ -209,45 +209,24 @@ class Photo extends \Zotlabs\Web\Controller { if(! $exists) { http_status_exit(404,'not found'); } - } } else http_status_exit(404,'not found'); } - + + if(! $data) + killme(); + header_remove('Pragma'); - - if($ismodified === gmdate("D, d M Y H:i:s", $modified) . " GMT") { + + 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($resolution)) { - switch($resolution) { - case 4: - $default = get_default_profile_photo(); - break; - case 5: - $default = get_default_profile_photo(80); - break; - case 6: - $default = get_default_profile_photo(48); - break; - default: - killme(); - // NOTREACHED - break; - } - $x = z_fetch_url(z_root() . '/' . $default,true,0,[ 'novalidate' => true ]); - $data = ($x['success'] ? $x['body'] : EMPTY_STR); - $mimetype = 'image/png'; - } } - + if(isset($res) && intval($res) && $res < 500) { $ph = photo_factory($data, $mimetype); if($ph->is_valid()) { -- cgit v1.2.3 From 1732b2dfe367e9e81bdfe1663383229f78f15572 Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Wed, 17 Apr 2019 23:15:46 +0200 Subject: Add 'must-revalidate' to Cache-control header for profile photos --- Zotlabs/Module/Photo.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 37dfa03e4..832edb6fe 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -41,6 +41,7 @@ class Photo extends \Zotlabs\Web\Controller { $observer_xchan = get_observer_hash(); $ismodified = $_SERVER['HTTP_IF_MODIFIED_SINCE']; + $cachecontrol = ''; if(isset($type)) { @@ -104,6 +105,8 @@ class Photo extends \Zotlabs\Web\Controller { $data = ($x['success'] ? $x['body'] : EMPTY_STR); $mimetype = 'image/png'; } + + $cachecontrol = ', must-revalidate'; } else { @@ -263,7 +266,7 @@ class Photo extends \Zotlabs\Web\Controller { $maxage = $expires - time(); header("Expires: " . gmdate("D, d M Y H:i:s", $expires) . " GMT"); - header("Cache-Control: max-age=" . $maxage); + header("Cache-Control: max-age=" . $maxage . $cachecontrol); } -- cgit v1.2.3 From 7a9093f634b0bbe9237cd18ea9a4d6d0b1b7c70a Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 18 Apr 2019 09:50:37 +0200 Subject: Implement ETag: header support for cache control --- Zotlabs/Module/Photo.php | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 832edb6fe..5e52bcf28 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -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,14 +95,14 @@ 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'; } else { @@ -212,24 +209,25 @@ class Photo extends \Zotlabs\Web\Controller { if(! $exists) { http_status_exit(404,'not found'); } + } } else http_status_exit(404,'not found'); } - - if(! $data) - killme(); - + + if(! $data) + killme(); + 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'); http_status_exit(304,'not modified'); } - + if(isset($res) && intval($res) && $res < 500) { $ph = photo_factory($data, $mimetype); if($ph->is_valid()) { @@ -266,12 +264,13 @@ class Photo extends \Zotlabs\Web\Controller { $maxage = $expires - time(); header("Expires: " . gmdate("D, d M Y H:i:s", $expires) . " GMT"); - header("Cache-Control: max-age=" . $maxage . $cachecontrol); + header("Cache-Control: max-age=" . $maxage . $cachecontrol); } 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. -- cgit v1.2.3 From eb02d01eede6739550a3ad4ef1d17d559c02528c Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 18 Apr 2019 10:13:03 +0200 Subject: Update Photo.php --- Zotlabs/Module/Photo.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 5e52bcf28..40c36e8fe 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -99,8 +99,10 @@ class Photo extends \Zotlabs\Web\Controller { } if(! $data) { - header("Location: " . z_root() . '/' . $default); - killme(); + $x = z_fetch_url(z_root() . '/' . $default, true, 0, [ 'novalidate' => true ]); + $data = ($x['success'] ? $x['body'] : EMPTY_STR); + $mimetype = 'image/png'; + $modified = filemtime($default); } $cachecontrol = ', must-revalidate'; -- cgit v1.2.3 From db020ca1a309cd2d8304b0c7fe25a73bb77bdbce Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 18 Apr 2019 21:55:06 +0200 Subject: Update Photo.php --- Zotlabs/Module/Photo.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs/Module') diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php index 40c36e8fe..7e25e08b2 100644 --- a/Zotlabs/Module/Photo.php +++ b/Zotlabs/Module/Photo.php @@ -223,7 +223,7 @@ class Photo extends \Zotlabs\Web\Controller { header_remove('Pragma'); - if($_SERVER['HTTP_IF_NONE_MATCH'] == md5($data) || $_SERVER['HTTP_IF_MODIFIED_SINCE'] === 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'); -- cgit v1.2.3