OSDN Git Service

[modify]ダンプ・スクリーンショットの表示をEtagによるキャッシュコントロールに対応
authorHabu <habu@users.sourceforge.jp>
Thu, 15 Mar 2018 11:49:02 +0000 (20:49 +0900)
committerHabu <habu@users.sourceforge.jp>
Thu, 15 Mar 2018 11:49:02 +0000 (20:49 +0900)
dump_file.inc

index 3881839..8c02ad6 100644 (file)
@@ -15,14 +15,23 @@ class DumpFile
             return;
         }
 
-        $content_encoding = self::get_content_encoding();
+        $contents = file_get_contents($filename);
+        $etag = md5($contents);
+
+        if ($etag === filter_input(INPUT_SERVER, 'HTTP_IF_NONE_MATCH')) {
+            http_response_code(304);
+            return;
+        }
 
+        $content_encoding = self::get_content_encoding();
+        header("Etag: ".$etag);
         header("Content-Type: ".$content_type);
+
         if ($content_encoding !== FALSE) {
             header("Content-Encoding: ".$content_encoding);
-            readfile($filename);
+            echo $contents;
         } else {
-            readgzfile($filename);
+            echo gzdecode($contents);
         }
     }