summaryrefslogtreecommitdiffstats
path: root/application
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2012-05-01 21:45:12 +0200
committerFlorian Pritz <bluewind@xinu.at>2012-05-01 21:45:12 +0200
commita89147c24dfd41420dd03405995b417d7b32a597 (patch)
tree53571e0b4410ea4d5ecfb5e3ed82f375161da2db /application
parentfee3b8cdb62d95d4aa32e52e79e2e72238d5d987 (diff)
move etag handling into handle_etag()
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application')
-rw-r--r--application/models/file_mod.php50
1 files changed, 23 insertions, 27 deletions
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");