From 6e80330e19ea8385da35b170f508556cfadf0340 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 29 Jun 2009 21:16:42 -0700 Subject: Remove the testing code to force rebuilding the cache. --- modules/gallery/libraries/Gallery_View.php | 1 - 1 file changed, 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/libraries/Gallery_View.php b/modules/gallery/libraries/Gallery_View.php index 40d78f94..32d79ac3 100644 --- a/modules/gallery/libraries/Gallery_View.php +++ b/modules/gallery/libraries/Gallery_View.php @@ -90,7 +90,6 @@ class Gallery_View_Core extends View { $cache = Cache::instance(); $contents = $cache->get($key); - $contents = ""; if (empty($contents)) { $contents = ""; foreach ($links as $link) { -- cgit v1.2.3 From 980c589e3d674b31a2ee734e2767b6460edfc4da Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 29 Jun 2009 21:38:04 -0700 Subject: Fix a few more issues 1) Don't use $_SERVER, use Input::instance()->server(). This fixes the problem that when you use a browser that doesn't pass in an Accept-Encoding, we'd barf on a missing array key 2) Don't bother looking up the _gz key if we don't have gzencode, because we probably didn't store one. 3) Only emit the gzip Content-Encoding header if we're actually sending back gzipped data. --- modules/gallery/controllers/combined.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'modules') diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index 9df74638..58ed85d0 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -40,8 +40,10 @@ class Combined_Controller extends Controller { * @param string the key (typically an md5 sum) */ private function _emit($type, $key) { + $input = Input::instance(); + // Our data is immutable, so if they already have a copy then it needs no updating. - if (!empty($_SERVER["HTTP_IF_MODIFIED_SINCE"])) { + if ($input->server("HTTP_IF_MODIFIED_SINCE")) { header('HTTP/1.0 304 Not Modified'); return; } @@ -54,23 +56,20 @@ class Combined_Controller extends Controller { Session::abort_save(); $cache = Cache::instance(); - if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false ) { - $content = $cache->get("{$key}_gz"); - } - - if (!$content) { + $use_gzip = function_exists("gzencode") && + (strpos($input->server("HTTP_ACCEPT_ENCODING"), "gzip") !== false); + if ($use_gzip && $content = $cache->get("{$key}_gz")) { + header("Content-Encoding: gzip"); + header("Cache-Control: public"); + } else { + // Fall back to non-gzipped if we have to $content = $cache->get($key); } - if (!$content) { + if (empty($content)) { Kohana::show_404(); } - if (strpos($_SERVER["HTTP_ACCEPT_ENCODING"], "gzip") !== false) { - header("Content-Encoding: gzip"); - header("Cache-Control: public"); - } - // $type is either 'javascript' or 'css' header("Content-Type: text/$type; charset=UTF-8"); header("Expires: Tue, 19 Jan 2038 00:00:00 GMT"); -- cgit v1.2.3 From 02b46833d60b462b70e3b00d6712059cc3547809 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 29 Jun 2009 21:52:42 -0700 Subject: Pass back Cache-Control and Expires headers when we send back a 304, otherwise some browsers (Firefox, at least) thinks that it needs to revalidate. At least in my case, it appears that my proxy tacks on restrictive Cache-Control headers if they aren't there. --- modules/gallery/controllers/combined.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index 58ed85d0..49a54f24 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -45,6 +45,9 @@ class Combined_Controller extends Controller { // Our data is immutable, so if they already have a copy then it needs no updating. if ($input->server("HTTP_IF_MODIFIED_SINCE")) { header('HTTP/1.0 304 Not Modified'); + header("Expires: Tue, 19 Jan 2038 00:00:00 GMT"); + header("Cache-Control: max-age=2678400"); + header('Pragma: public'); return; } @@ -60,7 +63,6 @@ class Combined_Controller extends Controller { (strpos($input->server("HTTP_ACCEPT_ENCODING"), "gzip") !== false); if ($use_gzip && $content = $cache->get("{$key}_gz")) { header("Content-Encoding: gzip"); - header("Cache-Control: public"); } else { // Fall back to non-gzipped if we have to $content = $cache->get($key); @@ -73,6 +75,8 @@ class Combined_Controller extends Controller { // $type is either 'javascript' or 'css' header("Content-Type: text/$type; charset=UTF-8"); header("Expires: Tue, 19 Jan 2038 00:00:00 GMT"); + header("Cache-Control: max-age=2678400"); + header('Pragma: public'); header("Last-Modified: " . gmdate("D, d M Y H:i:s T", time())); Kohana::close_buffers(false); -- cgit v1.2.3 From c9e8ff8fcb4c42948c8272ae367adda83957c101 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 29 Jun 2009 21:59:00 -0700 Subject: Use the appropriate content-type for javascript (application/javascript). --- modules/gallery/controllers/combined.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'modules') diff --git a/modules/gallery/controllers/combined.php b/modules/gallery/controllers/combined.php index 49a54f24..925d052d 100644 --- a/modules/gallery/controllers/combined.php +++ b/modules/gallery/controllers/combined.php @@ -73,7 +73,11 @@ class Combined_Controller extends Controller { } // $type is either 'javascript' or 'css' - header("Content-Type: text/$type; charset=UTF-8"); + if ($type == "javascript") { + header("Content-Type: application/javascript; charset=UTF-8"); + } else { + header("Content-Type: text/css; charset=UTF-8"); + } header("Expires: Tue, 19 Jan 2038 00:00:00 GMT"); header("Cache-Control: max-age=2678400"); header('Pragma: public'); -- cgit v1.2.3