From a89147c24dfd41420dd03405995b417d7b32a597 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Tue, 1 May 2012 21:45:12 +0200 Subject: move etag handling into handle_etag() Signed-off-by: Florian Pritz --- application/models/file_mod.php | 50 +++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 27 deletions(-) (limited to 'application/models') diff --git a/application/models/file_mod.php b/application/models/file_mod.php index e65529971..6030aefdd 100644 --- a/application/models/file_mod.php +++ b/application/models/file_mod.php @@ -195,6 +195,27 @@ class File_mod extends CI_Model { return true; } + private function handle_etag($etag) { + $etag = strtolower($etag); + $modified = true; + + if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) { + $oldtag = trim(strtolower($_SERVER['HTTP_IF_NONE_MATCH']), '"'); + if($oldtag == $etag) { + $modified = false; + } else { + $modified = true; + } + } + + header('Etag: "'.$etag.'"'); + + if (!$modified) { + header("HTTP/1.1 304 Not Modified"); + exit(); + } + } + // download a given ID // TODO: make smaller function download() @@ -216,31 +237,9 @@ class File_mod extends CI_Model { return; } - // MODIFIED SINCE SUPPORT -- START // helps to keep traffic low when reloading - $etag = strtolower($filedata["hash"]."-".$filedata["date"]); - $modified = true; - - // No need to check because different files have different IDs/hashes - if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { - $modified = false; - } - - if(isset($_SERVER['HTTP_IF_NONE_MATCH'])) { - $oldtag = trim(strtolower($_SERVER['HTTP_IF_NONE_MATCH']), '"'); - if($oldtag == $etag) { - $modified = false; - } else { - $modified = true; - } - } - - if (!$modified) { - header("HTTP/1.1 304 Not Modified"); - header('Etag: "'.$etag.'"'); - exit(); - } - // MODIFIED SINCE SUPPORT -- END + $etag = $filedata["hash"]."-".$filedata["date"]; + $this->handle_etag($etag); $type = $filedata['mimetype']; @@ -255,9 +254,6 @@ class File_mod extends CI_Model { // this is mainly used for compatibility $mode = $this->resolve_mode_alias($mode); - header("Last-Modified: ".date('D, d M Y H:i:s', $filedata["date"])." GMT"); - header('Etag: "'.$etag.'"'); - // create the qr code for /ID/ if ($mode == "qr") { header("Content-disposition: inline; filename=\"".$id."_qr.png\"\n"); -- cgit v1.2.3-24-g4f1b