Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattpiwik <matthieu.aubry@gmail.com>2011-05-06 01:23:12 +0400
committermattpiwik <matthieu.aubry@gmail.com>2011-05-06 01:23:12 +0400
commit0f0d9549d1cc2f324ef4029c3cd8f32b68b5d662 (patch)
tree16688cc1dbc0c58f52d91e645aac4ebc301ca90a
parent4c66a3c8edc0699ccd30a72f367cf035c5412108 (diff)
Fixes #2406
git-svn-id: http://dev.piwik.org/svn/trunk@4642 59fd770c-687e-43c8-a1e3-f5a4ff64c105
-rw-r--r--core/Piwik.php12
-rw-r--r--js/index.php4
-rw-r--r--tests/core/Piwik/serveStaticFile.test.php4
3 files changed, 15 insertions, 5 deletions
diff --git a/core/Piwik.php b/core/Piwik.php
index 976ba95eb6..e97dddf393 100644
--- a/core/Piwik.php
+++ b/core/Piwik.php
@@ -695,8 +695,10 @@ class Piwik
*
* @param string $file The location of the static file to serve
* @param string $contentType The content type of the static file.
+ * @param bool $expireFarFuture If set to true, will set Expires: header in far future.
+ * Should be set to false for files that don't have a cache buster (eg. piwik.js)
*/
- static public function serveStaticFile($file, $contentType)
+ static public function serveStaticFile($file, $contentType, $expireFarFuture = true)
{
if (file_exists($file))
{
@@ -720,7 +722,13 @@ class Piwik
self::overrideCacheControlHeaders('public');
@header('Vary: Accept-Encoding');
@header('Content-Disposition: inline; filename='.basename($file));
-
+
+ if($expireFarFuture)
+ {
+ // Required by proxy caches potentially in between the browser and server to cache the request indeed
+ @header("Expires: ".gmdate('D, d M Y H:i:s', time() + 86400 * 100) . ' GMT');
+ }
+
// Returns 304 if not modified since
if ($modifiedSince === $lastModified)
{
diff --git a/js/index.php b/js/index.php
index 94d68e5859..dd1b66d6ba 100644
--- a/js/index.php
+++ b/js/index.php
@@ -29,6 +29,8 @@ require_once PIWIK_INCLUDE_PATH . '/core/Piwik.php';
$file = '../piwik.js';
-Piwik::serveStaticFile($file, "application/javascript; charset=UTF-8");
+// There is no cache buster parameter so we don't set Expires: header
+$expireFarFuture = false;
+Piwik::serveStaticFile($file, "application/javascript; charset=UTF-8", $expireFarFuture);
exit;
diff --git a/tests/core/Piwik/serveStaticFile.test.php b/tests/core/Piwik/serveStaticFile.test.php
index 4d99ab50a8..a36ec69fa6 100644
--- a/tests/core/Piwik/serveStaticFile.test.php
+++ b/tests/core/Piwik/serveStaticFile.test.php
@@ -216,7 +216,7 @@ class Test_Piwik_serveStaticFile extends UnitTestCase
$pragma = $this->getPragma($fullResponse);
$this->assertTrue($pragma == null || $pragma == 'Pragma:');
$expires = $this->getExpires($fullResponse);
- $this->assertTrue($expires == null || $expires == 'Expires:');
+ $this->assertTrue(strtotime($expires) > time() + 99*86400);
}
/**
@@ -512,7 +512,7 @@ class Test_Piwik_serveStaticFile extends UnitTestCase
private function getExpires($fullResponse)
{
- preg_match_all('/(Expires:[[:print:]]*)/', $fullResponse, $matches);
+ preg_match_all('/Expires: ([[:print:]]*)/', $fullResponse, $matches);
if (isset($matches[1][0]))
{