]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Fixes #4895: Output valid ETag and Expires headers
authorSteve Clay <steve@mrclay.org>
Tue, 30 Oct 2012 00:59:21 +0000 (20:59 -0400)
committerSteve Clay <steve@mrclay.org>
Thu, 15 Nov 2012 06:42:15 +0000 (01:42 -0500)
engine/handlers/cache_handler.php
engine/lib/elgglib.php
mod/file/thumbnail.php
mod/groups/icon.php
mod/profile/icondirect.php
pages/avatar/view.php

index b332ec379f74debbd76ea86c82243887b3ae34f8..7706c2c92efd6e7e7a6d44a75f86249ec9a54340 100644 (file)
@@ -64,7 +64,7 @@ $ts = $matches[4];
 
 // If is the same ETag, content didn't changed.
 $etag = $ts;
-if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
+if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") {
        header("HTTP/1.1 304 Not Modified");
        exit;
 }
@@ -80,10 +80,10 @@ switch ($type) {
                break;
 }
 
-header('Expires: ' . date('r', strtotime("+6 months")), true);
+header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true);
 header("Pragma: public", true);
 header("Cache-Control: public", true);
-header("ETag: $etag");
+header("ETag: \"$etag\"");
 
 $filename = $dataroot . 'views_simplecache/' . md5($viewtype . $view);
 
index 974f38aadf12676d4abc29e078225d995002abe2..dd3cba25da7f7d09018dcc70714b3ec94c880c28 100644 (file)
@@ -1885,7 +1885,7 @@ function elgg_cacheable_view_page_handler($page, $type) {
                header("Content-type: $content_type");
 
                // @todo should js be cached when simple cache turned off
-               //header('Expires: ' . date('r', time() + 864000));
+               //header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
                //header("Pragma: public");
                //header("Cache-Control: public");
                //header("Content-Length: " . strlen($return));
index 35bf8c7f71d64e46ab8555f36d2d8e41e3316b5a..851f13a8fdad09bd6eb04065b4094f53365f8d54 100644 (file)
@@ -46,7 +46,7 @@ if ($simpletype == "image") {
 
                // caching images for 10 days
                header("Content-type: $mime");
-               header('Expires: ' . date('r',time() + 864000));
+               header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
                header("Pragma: public", true);
                header("Cache-Control: public", true);
                header("Content-Length: " . strlen($contents));
index 1bd240ea64c24bd17a9d1e8c943df581f7dbcbe4..ebdc1eb6df6e9addbeae042044420fc7c7276afd 100644 (file)
@@ -18,7 +18,7 @@ if (!($group instanceof ElggGroup)) {
 
 // If is the same ETag, content didn't changed.
 $etag = $group->icontime . $group_guid;
-if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
+if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") {
        header("HTTP/1.1 304 Not Modified");
        exit;
 }
@@ -46,9 +46,9 @@ if (!$success) {
 }
 
 header("Content-type: image/jpeg");
-header('Expires: ' . date('r',time() + 864000));
+header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+10 days")), true);
 header("Pragma: public");
 header("Cache-Control: public");
 header("Content-Length: " . strlen($contents));
-header("ETag: $etag");
+header("ETag: \"$etag\"");
 echo $contents;
index c4439f78c76bb083f84e612bfee3c867ae53b08c..dbab5d31ff5264e83cac49eade903e070e19a4a6 100644 (file)
@@ -23,7 +23,7 @@ $guid = (int)$_GET['guid'];
 
 // If is the same ETag, content didn't changed.
 $etag = $last_cache . $guid;
-if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
+if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == "\"$etag\"") {
        header("HTTP/1.1 304 Not Modified");
        exit;
 }
@@ -55,19 +55,15 @@ if ($mysql_dblink) {
                        $user_path = date('Y/m/d/', $join_date) . $guid;
 
                        $filename = "$data_root$user_path/profile/{$guid}{$size}.jpg";
-                       $contents = @file_get_contents($filename);
-                       if (!empty($contents)) {
+                       $size = @filesize($filename);
+                       if ($size) {
                                header("Content-type: image/jpeg");
-                               header('Expires: ' . date('r', strtotime("+6 months")), true);
+                               header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true);
                                header("Pragma: public");
                                header("Cache-Control: public");
-                               header("Content-Length: " . strlen($contents));
-                               header("ETag: $etag");
-                               // this chunking is done for supposedly better performance
-                               $split_string = str_split($contents, 1024);
-                               foreach ($split_string as $chunk) {
-                                       echo $chunk;
-                               }
+                               header("Content-Length: $size");
+                               header("ETag: \"$etag\"");
+                               readfile($filename);
                                exit;
                        }
                }
index bd6c9582154d7095ff4e0f057c53b043bb598342..10d81fef18d544e13c04786c2c5259db694df3a0 100644 (file)
@@ -46,7 +46,7 @@ if (!$success) {
 }
 
 header("Content-type: image/jpeg", true);
-header('Expires: ' . date('r', strtotime("+6 months")), true);
+header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', strtotime("+6 months")), true);
 header("Pragma: public", true);
 header("Cache-Control: public", true);
 header("Content-Length: " . strlen($contents));