aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Photo.php
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2019-04-24 21:11:19 +0200
committerMario <mario@mariovavti.com>2019-04-24 21:11:19 +0200
commite937e8fff96a935b14a479c062f6b0d00b90b99d (patch)
tree4c067a3b701ea56f10070c386b26a30f93666eb0 /Zotlabs/Module/Photo.php
parentf616b2d49a2d106ceb6cf4b1cea0e65a995ae394 (diff)
parentfe84dae313a21598882d52f3f36923b99180470c (diff)
downloadvolse-hubzilla-e937e8fff96a935b14a479c062f6b0d00b90b99d.tar.gz
volse-hubzilla-e937e8fff96a935b14a479c062f6b0d00b90b99d.tar.bz2
volse-hubzilla-e937e8fff96a935b14a479c062f6b0d00b90b99d.zip
Merge branch 'dev' into 'dev'
Add modification date in Etag hash calculation and optimize cached photos processing See merge request hubzilla/core!1607
Diffstat (limited to 'Zotlabs/Module/Photo.php')
-rw-r--r--Zotlabs/Module/Photo.php35
1 files changed, 21 insertions, 14 deletions
diff --git a/Zotlabs/Module/Photo.php b/Zotlabs/Module/Photo.php
index 7e25e08b2..30670c329 100644
--- a/Zotlabs/Module/Photo.php
+++ b/Zotlabs/Module/Photo.php
@@ -95,7 +95,7 @@ class Photo extends \Zotlabs\Web\Controller {
$default = $d['default'];
$data = $d['data'];
$mimetype = $d['mimetype'];
- $modified = time();
+ $modified = 0;
}
if(! $data) {
@@ -162,18 +162,20 @@ class Photo extends \Zotlabs\Web\Controller {
$allowed = (-1);
if($u === PHOTO_CACHE) {
// Validate cache
- $cache = array(
- 'resid' => $photo,
- 'status' => false
- );
- if($cache_mode['on'])
+ if($cache_mode['on']) {
+ $cache = array(
+ 'resid' => $photo,
+ 'status' => false
+ );
call_hooks('cache_url_hook', $cache);
- if(! $cache['status']) {
- $url = htmlspecialchars_decode($r[0]['display_path']);
- if(strpos(z_root(),'https:') !== false && strpos($url,'https:') === false)
- $url = z_root() . '/sslify/' . $filename . '?f=&url=' . urlencode($url);
- header("Location: " . $url);
- killme();
+ if(! $cache['status']) {
+ $url = htmlspecialchars_decode($r[0]['display_path']);
+ // SSLify if needed
+ if(strpos(z_root(),'https:') !== false && strpos($url,'https:') === false)
+ $url = z_root() . '/sslify/' . $filename . '?f=&url=' . urlencode($url);
+ header("Location: " . $url);
+ killme();
+ }
}
}
}
@@ -220,10 +222,15 @@ class Photo extends \Zotlabs\Web\Controller {
if(! $data)
killme();
+
+ $etag = md5($data . $modified);
+
+ if($modified == 0)
+ $modified = time();
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'] === $etag || $_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,7 +279,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("ETag: " . $etag);
header("Content-Length: " . (isset($filesize) ? $filesize : strlen($data)));
// If it's a file resource, stream it.