From 5c56d816dd3eb16e8ecdabd100643a5f396fd46a Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Thu, 17 Sep 2015 14:52:47 +0200 Subject: do not suppress errors inside included files --- itjs.class | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'itjs.class') diff --git a/itjs.class b/itjs.class index 6ef1c8f..b8520f5 100644 --- a/itjs.class +++ b/itjs.class @@ -160,7 +160,8 @@ static function filecontents($filenames, $execphp = true) list($filename, $paramstr) = explode("?", $filename); if ($paramstr && $execphp) parse_str($paramstr, $_GET); - $result .= it::replace(array('^1$' => ""), $execphp ? @include($filename) : @file_get_contents($filename), array('utf8' => false)); + if (file_exists($filename)) + $result .= it::replace(array('^1$' => ""), $execphp ? include($filename) : file_get_contents($filename), array('utf8' => false)); $_GET = $origget; } $result .= ob_get_clean(); -- cgit v1.2.3 From 9aab17be924ec04b7b46a971d3c9f414f6eb9bf0 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 28 Oct 2015 18:51:39 +0100 Subject: extract far future header handling for ffe.php --- itjs.class | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'itjs.class') diff --git a/itjs.class b/itjs.class index b8520f5..f76620f 100644 --- a/itjs.class +++ b/itjs.class @@ -217,6 +217,26 @@ function crcurl($url) return it::match('#', $url) ? U(trim($url, "#")) : U($url, array('c' => self::checksum(array($fn)))); } +static function far_future_headers() +{ + $crc = $_REQUEST['c'] ?: $_REQUEST['s']; + if ($crc != "-" && !$_SERVER['HTTP_CACHE_CONTROL'] && $_SERVER['HTTP_IF_NONE_MATCH'] && !it::is_devel() && !$_REQUEST['retry']) + { + header("HTTP/1.0 304 Not Modified"); # client should always keep the component that fits the page it has + exit; + } + + if ($crc != "-") + @header("Etag: alwaysvalid"); # we have checksums in the url. client should always keep the version he downloaded along with the html + + if (it::is_live() && !$_REQUEST['retry']) + { + $keeptime = $crc == "-" ? 0 : ($crc ? 30*86400 : 900); # long expire if checksum present + header("Cache-Control: max-age=$keeptime, private"); # proxies should not cache since contents of same url can differ between browsers + header("Expires: " . gmdate("D, d M Y H:i:s", time() + $keeptime). " GMT"); + } +} + } ?> -- cgit v1.2.3 From 61d20830c3b154e343408c3206a8d01d4756789b Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Tue, 3 Nov 2015 19:15:14 +0100 Subject: dont omit long expire if url was recently redownloaded --- itjs.class | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'itjs.class') diff --git a/itjs.class b/itjs.class index f76620f..32c504b 100644 --- a/itjs.class +++ b/itjs.class @@ -207,14 +207,14 @@ static function checksum($fnlist, $p = array()) return it_cache::get($key) ?: it_cache::put($key, substr(md5(self::filecontents($filenames, false)), 0, 10), array('ttl' => 60)); } -function crcurl($url) +function crcurl($url, $p = []) { if (it::match('^http', $url)) # remote url, must fetch to crc - $fn = it_url::get_cache(array('url' => $url, 'maxage' => 3600)); + list($fn, $short_expire) = array(it_url::get_cache(array('url' => $url, 'maxage' => 3600) + $p), false); else - $fn = ($m = it::match("^//(\w+)(/.*)", $url)) ? "/www/$m[0].search.ch" . $m[1] : $GLOBALS['ULTRAHOME'] . $url; + list($fn, $short_expire) = array(($m = it::match("^//(\w+)(/.*)", $url)) ? "/www/$m[0].search.ch" . $m[1] : $GLOBALS['ULTRAHOME'] . $url, true);; - return it::match('#', $url) ? U(trim($url, "#")) : U($url, array('c' => self::checksum(array($fn)))); + return it::match('#', $url) ? U(trim($url, "#")) : U($url, array('c' => self::checksum(array($fn), array('short_expire' => $short_expire)))); } static function far_future_headers() -- cgit v1.2.3 From 8007fdcdd2ac074b6e0fc5076e160d83dde8d6a3 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 9 Nov 2015 14:34:17 +0100 Subject: php4 --- itjs.class | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'itjs.class') diff --git a/itjs.class b/itjs.class index 32c504b..e69696a 100644 --- a/itjs.class +++ b/itjs.class @@ -207,7 +207,7 @@ static function checksum($fnlist, $p = array()) return it_cache::get($key) ?: it_cache::put($key, substr(md5(self::filecontents($filenames, false)), 0, 10), array('ttl' => 60)); } -function crcurl($url, $p = []) +function crcurl($url, $p = array()) { if (it::match('^http', $url)) # remote url, must fetch to crc list($fn, $short_expire) = array(it_url::get_cache(array('url' => $url, 'maxage' => 3600) + $p), false); -- cgit v1.2.3 From 4179279e4bb7e654ba44924821a2fdd62e1e1846 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 16 Nov 2015 13:59:53 +0100 Subject: make c= optional for far future expire --- itjs.class | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'itjs.class') diff --git a/itjs.class b/itjs.class index e69696a..92a1c58 100644 --- a/itjs.class +++ b/itjs.class @@ -217,7 +217,8 @@ function crcurl($url, $p = array()) return it::match('#', $url) ? U(trim($url, "#")) : U($url, array('c' => self::checksum(array($fn), array('short_expire' => $short_expire)))); } -static function far_future_headers() +# $p['nocrc'] means no $_REQUEST['c'] is needed for far future expire +static function far_future_headers($p = []) { $crc = $_REQUEST['c'] ?: $_REQUEST['s']; if ($crc != "-" && !$_SERVER['HTTP_CACHE_CONTROL'] && $_SERVER['HTTP_IF_NONE_MATCH'] && !it::is_devel() && !$_REQUEST['retry']) @@ -231,7 +232,7 @@ static function far_future_headers() if (it::is_live() && !$_REQUEST['retry']) { - $keeptime = $crc == "-" ? 0 : ($crc ? 30*86400 : 900); # long expire if checksum present + $keeptime = $crc == "-" ? 0 : ($crc || $p['nocrc'] ? 30*86400 : 900); # long expire if checksum present header("Cache-Control: max-age=$keeptime, private"); # proxies should not cache since contents of same url can differ between browsers header("Expires: " . gmdate("D, d M Y H:i:s", time() + $keeptime). " GMT"); } -- cgit v1.2.3 From 3b4aeabd9186666e025d3233f06f7458356bfc37 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Mon, 16 Nov 2015 14:00:23 +0100 Subject: make c= optional for far future expire --- itjs.class | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'itjs.class') diff --git a/itjs.class b/itjs.class index 92a1c58..c54abd3 100644 --- a/itjs.class +++ b/itjs.class @@ -218,7 +218,7 @@ function crcurl($url, $p = array()) } # $p['nocrc'] means no $_REQUEST['c'] is needed for far future expire -static function far_future_headers($p = []) +static function far_future_headers($p = array()) { $crc = $_REQUEST['c'] ?: $_REQUEST['s']; if ($crc != "-" && !$_SERVER['HTTP_CACHE_CONTROL'] && $_SERVER['HTTP_IF_NONE_MATCH'] && !it::is_devel() && !$_REQUEST['retry']) -- cgit v1.2.3