Skip to content

Commit

Permalink
Fix a few more issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bharat committed Jun 30, 2009
1 parent 6e80330 commit 980c589
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions modules/gallery/controllers/combined.php
Expand Up @@ -40,8 +40,10 @@ public function css($key) {
* @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;
}
Expand All @@ -54,23 +56,20 @@ private function _emit($type, $key) {
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");
Expand Down

0 comments on commit 980c589

Please sign in to comment.