diff options
-rw-r--r-- | application/controllers/Main.php | 30 | ||||
-rw-r--r-- | application/helpers/filebin_helper.php | 22 |
2 files changed, 26 insertions, 26 deletions
diff --git a/application/controllers/Main.php b/application/controllers/Main.php index c0aded275..b0f88753e 100644 --- a/application/controllers/Main.php +++ b/application/controllers/Main.php @@ -37,6 +37,28 @@ class Main extends MY_Controller { } } + 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(); + } + } + /** * Generate a page title of the format "Multipaste - $filename, $filename, … (N more)". * This mainly helps in IRC channels to quickly determine what is in a multipaste. @@ -121,7 +143,7 @@ class Main extends MY_Controller { break; case "qr": - handle_etag($etag); + $this->_handle_etag($etag); header("Content-disposition: inline; filename=\"".$id."_qr.png\"\n"); header("Content-Type: image/png\n"); $qr = new \Endroid\QrCode\QrCode(); @@ -156,7 +178,7 @@ class Main extends MY_Controller { // user wants the plain file if ($lexer == 'plain') { assert(count($files) == 1); - handle_etag($etag); + $this->_handle_etag($etag); $filedata = $files[0]; $filepath = $this->mfile->file($filedata["data_id"]); @@ -199,7 +221,7 @@ class Main extends MY_Controller { foreach (array("X-WebKit-CSP", "X-Content-Security-Policy", "Content-Security-Policy") as $header_name) { header("$header_name: default-src 'none'; img-src *; media-src *; font-src *; style-src 'unsafe-inline' *; script-src 'none'; object-src *; frame-src 'none'; "); } - handle_etag($etag); + $this->_handle_etag($etag); $this->ddownload->serveFile($file, $filedata["filename"], $filedata["mimetype"]); exit(); } else { @@ -472,7 +494,7 @@ class Main extends MY_Controller { } $etag = "$id-thumb"; - handle_etag($etag); + $this->_handle_etag($etag); $thumb_size = 150; $cache_timeout = 60*60*24*30; # 1 month diff --git a/application/helpers/filebin_helper.php b/application/helpers/filebin_helper.php index b3e0e3ed9..847d6d3ae 100644 --- a/application/helpers/filebin_helper.php +++ b/application/helpers/filebin_helper.php @@ -114,28 +114,6 @@ function js_cache_buster() return $ret; } -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(); - } -} - // Reference: http://php.net/manual/en/features.file-upload.multiple.php#109437 // This is a little different because we don't care about the fieldname function getNormalizedFILES() |