diff --git a/core/AssetManager.php b/core/AssetManager.php index e65639b12f917dbbed52206608c229d6f879c1a0..af8e8a4bd4e6e735582c6aaacd92a89ea92d1568 100644 --- a/core/AssetManager.php +++ b/core/AssetManager.php @@ -500,7 +500,7 @@ class AssetManager } // Tries to remove compressed version of the merged file. - // See Piwik::serveFile() for more info on static file compression + // See Piwik::serverStaticFile() for more info on static file compression $compressedFileLocation = PIWIK_USER_PATH . Piwik::COMPRESSED_FILE_LOCATION . $filename; @unlink($compressedFileLocation . ".deflate"); diff --git a/core/DataTable/Renderer/Csv.php b/core/DataTable/Renderer/Csv.php index 64a62e3c2a4d46d388c28aac7c950d3fc5b7cf07..e1f4556025a621966155c343e30d1d6e69e0e322 100644 --- a/core/DataTable/Renderer/Csv.php +++ b/core/DataTable/Renderer/Csv.php @@ -10,14 +10,14 @@ */ namespace Piwik\DataTable\Renderer; -use Piwik\DataTable\Simple; +use Piwik\Common; use Piwik\DataTable\Renderer; +use Piwik\DataTable\Simple; +use Piwik\DataTable; +use Piwik\Date; use Piwik\Period; use Piwik\Period\Range; -use Piwik\Piwik; -use Piwik\Common; -use Piwik\Date; -use Piwik\DataTable; +use Piwik\ProxyHttp; /** * CSV export @@ -353,7 +353,7 @@ class Csv extends Renderer // silent fail otherwise unit tests fail @header('Content-Type: application/vnd.ms-excel'); @header('Content-Disposition: attachment; filename="' . $fileName . '"'); - Piwik::overrideCacheControlHeaders(); + ProxyHttp::overrideCacheControlHeaders(); } /** diff --git a/core/DataTable/Renderer/Json.php b/core/DataTable/Renderer/Json.php index 89dd73ab376818ba7d20d87700cd843da97d524f..ad22cab3ad793b98796e3e0899f1abb8eeb6fb4e 100644 --- a/core/DataTable/Renderer/Json.php +++ b/core/DataTable/Renderer/Json.php @@ -10,11 +10,10 @@ */ namespace Piwik\DataTable\Renderer; -use Piwik\DataTable\Renderer; -use Piwik\Piwik; use Piwik\Common; +use Piwik\DataTable\Renderer; use Piwik\DataTable; -use Piwik\DataTable\Renderer\Php; +use Piwik\ProxyHttp; /** * JSON export. @@ -114,7 +113,7 @@ class Json extends Renderer protected function renderHeader() { self::sendHeaderJSON(); - Piwik::overrideCacheControlHeaders(); + ProxyHttp::overrideCacheControlHeaders(); } public static function sendHeaderJSON() diff --git a/core/FrontController.php b/core/FrontController.php index 79a57b5e93f5ec3cc75524da91e3ee9ecae9520d..b26a7548082f34aaa29e137b74e6350b9400071f 100644 --- a/core/FrontController.php +++ b/core/FrontController.php @@ -15,7 +15,6 @@ use Piwik\API\Request; use Piwik\API\ResponseBuilder; use Piwik\Log; use Piwik\Session; -use Piwik\Profiler; use Zend_Registry; /** @@ -344,7 +343,7 @@ class FrontController { if (!Common::isPhpCliMode() && Config::getInstance()->General['force_ssl'] == 1 - && !Piwik::isHttps() + && !ProxyHttp::isHttps() // Specifically disable for the opt out iframe && !(Common::getRequestVar('module', '') == 'CoreAdminHome' && Common::getRequestVar('action', '') == 'optOut') diff --git a/core/Piwik.php b/core/Piwik.php index 6d178f45eb72c20643da125c1e23c85132ccf072..469b1f80e64f77585962ea8e46cc310f0142c1e5 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -178,42 +178,6 @@ class Piwik return $url; } - /** - * Returns true if this appears to be a secure HTTPS connection - * - * @return bool - */ - static public function isHttps() - { - return Url::getCurrentScheme() === 'https'; - } - - /** - * Workaround IE bug when downloading certain document types over SSL and - * cache control headers are present, e.g., - * - * Cache-Control: no-cache - * Cache-Control: no-store,max-age=0,must-revalidate - * Pragma: no-cache - * - * @see http://support.microsoft.com/kb/316431/ - * @see RFC2616 - * - * @param string $override One of "public", "private", "no-cache", or "no-store". (optional) - */ - static public function overrideCacheControlHeaders($override = null) - { - if ($override || self::isHttps()) { - @header('Pragma: '); - @header('Expires: '); - if (in_array($override, array('public', 'private', 'no-cache', 'no-store'))) { - @header("Cache-Control: $override, must-revalidate"); - } else { - @header('Cache-Control: must-revalidate'); - } - } - } - /* * File and directory operations */ diff --git a/core/ProxyHttp.php b/core/ProxyHttp.php new file mode 100644 index 0000000000000000000000000000000000000000..5bcde43de1dbc0f591f0e3ce4bdd546799cd8ff1 --- /dev/null +++ b/core/ProxyHttp.php @@ -0,0 +1,233 @@ +<?php +/** + * Piwik - Open source web analytics + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + * + * @category Piwik + * @package Piwik + */ +namespace Piwik; + +/** + * Http helper: static file server proxy, with compression, caching, isHttps() helper... + * + * Used to server piwik.js and the merged+minified CSS and JS files + * + * @package Piwik + */ +class ProxyHttp +{ + /** + * Returns true if the current request appears to be a secure HTTPS connection + * + * @return bool + */ + public static function isHttps() + { + return Url::getCurrentScheme() === 'https'; + } + + /** + * Serve static files through php proxy. + * + * It performs the following actions: + * - Checks the file is readable or returns "HTTP/1.0 404 Not Found" + * - Returns "HTTP/1.1 304 Not Modified" after comparing the HTTP_IF_MODIFIED_SINCE + * with the modification date of the static file + * - Will try to compress the static file according to HTTP_ACCEPT_ENCODING. Compressed files are store in + * the /tmp directory. If compressing extensions are not available, a manually gzip compressed file + * can be provided in the /tmp directory. It has to bear the same name with an added .gz extension. + * Using manually compressed static files requires you to manually update the compressed file when + * the static file is updated. + * - Overrides server cache control config to allow caching + * - Sends Very Accept-Encoding to tell proxies to store different version of the static file according + * to users encoding capacities. + * + * Warning: + * Compressed filed are stored in the /tmp directory. + * If this method is used with two files bearing the same name but located in different locations, + * there is a risk of conflict. One file could be served with the content of the other. + * A future upgrade of this method would be to recreate the directory structure of the static file + * within a /tmp/compressed-static-files directory. + * + * @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) + */ + public static function serverStaticFile($file, $contentType, $expireFarFuture = true) + { + if (file_exists($file)) { + // conditional GET + $modifiedSince = ''; + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) { + $modifiedSince = $_SERVER['HTTP_IF_MODIFIED_SINCE']; + + // strip any trailing data appended to header + if (false !== ($semicolon = strpos($modifiedSince, ';'))) { + $modifiedSince = substr($modifiedSince, 0, $semicolon); + } + } + + $fileModifiedTime = @filemtime($file); + $lastModified = gmdate('D, d M Y H:i:s', $fileModifiedTime) . ' GMT'; + + // set HTTP response headers + 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) { + self::setHttpStatus('304 Not Modified'); + } else { + // optional compression + $compressed = false; + $encoding = ''; + $compressedFileLocation = PIWIK_USER_PATH . Piwik::COMPRESSED_FILE_LOCATION . basename($file); + + $phpOutputCompressionEnabled = ProxyHttp::isPhpOutputCompressed(); + if (isset($_SERVER['HTTP_ACCEPT_ENCODING']) && !$phpOutputCompressionEnabled) { + $acceptEncoding = $_SERVER['HTTP_ACCEPT_ENCODING']; + + if (extension_loaded('zlib') && function_exists('file_get_contents') && function_exists('file_put_contents')) { + if (preg_match('/(?:^|, ?)(deflate)(?:,|$)/', $acceptEncoding, $matches)) { + $encoding = 'deflate'; + $filegz = $compressedFileLocation . '.deflate'; + } else if (preg_match('/(?:^|, ?)((x-)?gzip)(?:,|$)/', $acceptEncoding, $matches)) { + $encoding = $matches[1]; + $filegz = $compressedFileLocation . '.gz'; + } + + if (!empty($encoding)) { + // compress-on-demand and use cache + if (!file_exists($filegz) || ($fileModifiedTime > @filemtime($filegz))) { + $data = file_get_contents($file); + + if ($encoding == 'deflate') { + $data = gzdeflate($data, 9); + } else if ($encoding == 'gzip' || $encoding == 'x-gzip') { + $data = gzencode($data, 9); + } + + file_put_contents($filegz, $data); + } + + $compressed = true; + $file = $filegz; + } + } else { + // manually compressed + $filegz = $compressedFileLocation . '.gz'; + if (preg_match('/(?:^|, ?)((x-)?gzip)(?:,|$)/', $acceptEncoding, $matches) && file_exists($filegz) && ($fileModifiedTime < @filemtime($filegz))) { + $encoding = $matches[1]; + $compressed = true; + $file = $filegz; + } + } + } + + @header('Last-Modified: ' . $lastModified); + + if (!$phpOutputCompressionEnabled) { + @header('Content-Length: ' . filesize($file)); + } + + if (!empty($contentType)) { + @header('Content-Type: ' . $contentType); + } + + if ($compressed) { + @header('Content-Encoding: ' . $encoding); + } + + if (!_readfile($file)) { + self::setHttpStatus('505 Internal server error'); + } + } + } else { + self::setHttpStatus('404 Not Found'); + } + } + + /** + * Test if php output is compressed + * + * @return bool True if php output is (or suspected/likely) to be compressed + */ + public static function isPhpOutputCompressed() + { + // Off = ''; On = '1'; otherwise, it's a buffer size + $zlibOutputCompression = ini_get('zlib.output_compression'); + + // could be ob_gzhandler, ob_deflatehandler, etc + $outputHandler = ini_get('output_handler'); + + // output handlers can be stacked + $obHandlers = array_filter(ob_list_handlers(), function ($var) { + return $var !== "default output handler"; + }); + + // user defined handler via wrapper + $autoPrependFile = ini_get('auto_prepend_file'); + $autoAppendFile = ini_get('auto_append_file'); + + return !empty($zlibOutputCompression) || + !empty($outputHandler) || + !empty($obHandlers) || + !empty($autoPrependFile) || + !empty($autoAppendFile); + } + + + /** + * Workaround IE bug when downloading certain document types over SSL and + * cache control headers are present, e.g., + * + * Cache-Control: no-cache + * Cache-Control: no-store,max-age=0,must-revalidate + * Pragma: no-cache + * + * @see http://support.microsoft.com/kb/316431/ + * @see RFC2616 + * + * @param string $override One of "public", "private", "no-cache", or "no-store". (optional) + */ + public static function overrideCacheControlHeaders($override = null) + { + if ($override || self::isHttps()) { + @header('Pragma: '); + @header('Expires: '); + if (in_array($override, array('public', 'private', 'no-cache', 'no-store'))) { + @header("Cache-Control: $override, must-revalidate"); + } else { + @header('Cache-Control: must-revalidate'); + } + } + } + + + /** + * Set response header, e.g., HTTP/1.0 200 Ok + * + * @param string $status Status + * @return bool + */ + protected static function setHttpStatus($status) + { + if (substr_compare(PHP_SAPI, '-fcgi', -5)) { + @header($_SERVER['SERVER_PROTOCOL'] . ' ' . $status); + } else { + // FastCGI + @header('Status: ' . $status); + } + } + +} \ No newline at end of file diff --git a/core/ReportRenderer.php b/core/ReportRenderer.php index f7249352097eb8134ab1485581c65f710dde319e..3287a6e97ee8a5b960f4bb91fd4e5b38b9f7beaa 100644 --- a/core/ReportRenderer.php +++ b/core/ReportRenderer.php @@ -11,12 +11,10 @@ namespace Piwik; use Exception; -use Piwik\DataTable\Simple; +use Piwik\API\Request; use Piwik\DataTable\Row; -use Piwik\Piwik; +use Piwik\DataTable\Simple; use Piwik\DataTable; -use Piwik\Loader; -use Piwik\API\Request; use Piwik\Plugins\ImageGraph\API; /** @@ -175,7 +173,7 @@ abstract class ReportRenderer { $filename = ReportRenderer::appendExtension($filename, $extension); - Piwik::overrideCacheControlHeaders(); + ProxyHttp::overrideCacheControlHeaders(); header('Content-Description: File Transfer'); header('Content-Type: ' . $contentType); header('Content-Disposition: attachment; filename="' . str_replace('"', '\'', basename($filename)) . '";'); diff --git a/core/Session.php b/core/Session.php index 16378607edce983efb8e8d275a6d45bb8c607409..59e02a89a27be2c014eb024dc5b1ea7b4fbe9ae2 100644 --- a/core/Session.php +++ b/core/Session.php @@ -11,9 +11,6 @@ namespace Piwik; use Exception; -use Piwik\Config; -use Piwik\Piwik; -use Piwik\Common; use Piwik\Session\SaveHandler\DbTable; use Zend_Registry; use Zend_Session; @@ -63,7 +60,7 @@ class Session extends Zend_Session @ini_set('session.use_only_cookies', '1'); // advise browser that session cookie should only be sent over secure connection - if (Piwik::isHttps()) { + if (ProxyHttp::isHttps()) { @ini_set('session.cookie_secure', '1'); } diff --git a/core/View.php b/core/View.php index fea23de6ac429f739e32ea4a122beffa352141ed..910e5b1397078f4c9e6b2de0d3dd0ba3d0810c5b 100644 --- a/core/View.php +++ b/core/View.php @@ -134,7 +134,7 @@ class View implements ViewInterface $this->totalNumberOfQueries = 0; } - Piwik::overrideCacheControlHeaders('no-store'); + ProxyHttp::overrideCacheControlHeaders('no-store'); @header('Content-Type: ' . $this->contentType); // always sending this header, sometimes empty, to ensure that Dashboard embed loads (which could call this header() multiple times, the last one will prevail) diff --git a/js/index.php b/js/index.php index 4ee43b7e644c5812b00db3fed41c604ee9a61e45..721e3353ef7d480cd841ee5f6d4906b4f757bdc3 100644 --- a/js/index.php +++ b/js/index.php @@ -5,7 +5,7 @@ * @link http://piwik.org * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later */ -use Piwik\ProxyStaticFile; +use Piwik\ProxyHttp; /** * Tracker proxy @@ -31,6 +31,6 @@ $file = '../piwik.js'; // There is no cache buster parameter so we don't set Expires: header $expireFarFuture = false; -ProxyStaticFile::serveFile($file, "application/javascript; charset=UTF-8", $expireFarFuture); +ProxyHttp::serverStaticFile($file, "application/javascript; charset=UTF-8", $expireFarFuture); exit; diff --git a/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php b/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php index 0f0cccb22c723af44fb4c1caa94de4bc283daf95..b3253b340c4f83e05dbefee80ac8f56625d20027 100644 --- a/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php +++ b/plugins/CoreVisualizations/JqplotDataGenerator/Chart.php @@ -10,8 +10,8 @@ */ namespace Piwik\Plugins\CoreVisualizations\JqplotDataGenerator; -use Piwik\Piwik; use Piwik\Common; +use Piwik\ProxyHttp; /** * Generates the data in the Open Flash Chart format, from the given data. @@ -106,7 +106,7 @@ class Chart public function render() { - Piwik::overrideCacheControlHeaders(); + ProxyHttp::overrideCacheControlHeaders(); // See http://www.jqplot.com/docs/files/jqPlotOptions-txt.html $data = array( diff --git a/plugins/Installation/Controller.php b/plugins/Installation/Controller.php index 295fcfd776c4fa647d80c1ccb900e61364a43a63..5df88f94f48a34e9b751e5276b77cad1954a0fec 100644 --- a/plugins/Installation/Controller.php +++ b/plugins/Installation/Controller.php @@ -11,26 +11,23 @@ namespace Piwik\Plugins\Installation; use Exception; +use Piwik\Access; use Piwik\API\Request; +use Piwik\Common; +use Piwik\Config; use Piwik\DataAccess\ArchiveTableCreator; use Piwik\Db\Adapter; -use Piwik\Piwik; -use Piwik\Config; -use Piwik\Common; -use Piwik\Access; -use Piwik\Http; -use Piwik\Session\SessionNamespace; -use Piwik\Updater; -use Piwik\Version; -use Piwik\Url; -use Piwik\ProxyHeaders; use Piwik\Db; -use Piwik\Plugins\Installation\FormDatabaseSetup; -use Piwik\Plugins\Installation\FormFirstWebsiteSetup; -use Piwik\Plugins\Installation\FormGeneralSetup; +use Piwik\Http; +use Piwik\Piwik; use Piwik\Plugins\LanguagesManager\LanguagesManager; use Piwik\Plugins\SitesManager\API as SitesManagerAPI; use Piwik\Plugins\UsersManager\API as UsersManagerAPI; +use Piwik\ProxyHeaders; +use Piwik\Session\SessionNamespace; +use Piwik\Updater; +use Piwik\Url; +use Piwik\Version; use Zend_Db_Adapter_Exception; /** @@ -850,7 +847,7 @@ class Controller extends \Piwik\Controller\Admin $infos['tracker_status'] = Common::getRequestVar('trackerStatus', 0, 'int'); $infos['protocol'] = ProxyHeaders::getProtocolInformation(); - if (!Piwik::isHttps() && $infos['protocol'] !== null) { + if (!\Piwik\ProxyHttp::isHttps() && $infos['protocol'] !== null) { $infos['general_infos']['assume_secure_protocol'] = '1'; } if (count($headers = ProxyHeaders::getProxyClientHeaders()) > 0) { diff --git a/plugins/Login/Controller.php b/plugins/Login/Controller.php index 9ed0e7c3cf48a528f4ec6f80e6246a045a5e3a6e..ad4e91c1d1a1dc842c3adf6867ef5c9715a2cff2 100644 --- a/plugins/Login/Controller.php +++ b/plugins/Login/Controller.php @@ -11,22 +11,20 @@ namespace Piwik\Plugins\Login; use Exception; -use Piwik\Config; -use Piwik\Piwik; use Piwik\Common; +use Piwik\Config; use Piwik\Cookie; use Piwik\IP; use Piwik\Mail; use Piwik\Nonce; -use Piwik\View; -use Piwik\Url; +use Piwik\Piwik; +use Piwik\Plugins\UsersManager\API; +use Piwik\Plugins\UsersManager\UsersManager; +use Piwik\ProxyHttp; use Piwik\QuickForm2; use Piwik\Session; -use Piwik\Plugins\Login\Login; -use Piwik\Plugins\Login\FormLogin; -use Piwik\Plugins\Login\FormResetPassword; -use Piwik\Plugins\UsersManager\UsersManager; -use Piwik\Plugins\UsersManager\API; +use Piwik\Url; +use Piwik\View; require_once PIWIK_INCLUDE_PATH . '/core/Config.php'; @@ -499,7 +497,7 @@ class Controller extends \Piwik\Controller { $forceSslLogin = Config::getInstance()->General['force_ssl_login']; if ($forceSslLogin - && !Piwik::isHttps() + && !ProxyHttp::isHttps() ) { $url = 'https://' . Url::getCurrentHost() diff --git a/plugins/Login/Login.php b/plugins/Login/Login.php index 2e511b0a5bacb4ef40b25306f2914f2a2efbe1f5..653b5bfb60ee54720c4ebdfab151936a88267061 100644 --- a/plugins/Login/Login.php +++ b/plugins/Login/Login.php @@ -12,14 +12,13 @@ namespace Piwik\Plugins\Login; use Exception; use Piwik\Config; -use Piwik\Piwik; use Piwik\Cookie; use Piwik\Option; -use Piwik\Plugins\Login\Auth; -use Piwik\Plugins\Login\Controller; -use Piwik\Session; -use Piwik\Plugins\UsersManager\UsersManager; +use Piwik\Piwik; use Piwik\Plugins\UsersManager\API; +use Piwik\Plugins\UsersManager\UsersManager; +use Piwik\ProxyHttp; +use Piwik\Session; /** * @@ -124,7 +123,7 @@ class Login extends \Piwik\Plugin $cookie->set('login', $login); $cookie->set('token_auth', $auth->getHashTokenAuth($login, $authResult->getTokenAuth())); - $cookie->setSecure(Piwik::isHttps()); + $cookie->setSecure(ProxyHttp::isHttps()); $cookie->setHttpOnly(true); $cookie->save(); diff --git a/plugins/Overlay/Controller.php b/plugins/Overlay/Controller.php index 3721c9b22664a41060af20c7ff9c0cdea592084a..128ba12e6bf35f5fb22052e22e3937397c86189b 100644 --- a/plugins/Overlay/Controller.php +++ b/plugins/Overlay/Controller.php @@ -11,14 +11,15 @@ namespace Piwik\Plugins\Overlay; use Piwik\API\Request; +use Piwik\Common; +use Piwik\Config; use Piwik\Metrics; use Piwik\Piwik; -use Piwik\Config; -use Piwik\Common; use Piwik\Plugins\Actions\ArchivingHelper; +use Piwik\Plugins\SitesManager\API; +use Piwik\ProxyHttp; use Piwik\Tracker\Action; use Piwik\View; -use Piwik\Plugins\SitesManager\API; class Controller extends \Piwik\Controller { @@ -41,7 +42,7 @@ class Controller extends \Piwik\Controller $view->date = Common::getRequestVar('date', 'today'); $view->period = Common::getRequestVar('period', 'day'); - $view->ssl = Piwik::isHttps(); + $view->ssl = ProxyHttp::isHttps(); echo $view->render(); } @@ -137,7 +138,7 @@ class Controller extends \Piwik\Controller <html><head><title></title></head><body> <script type="text/javascript"> function handleProtocol(url) { - if (' . (Piwik::isHttps() ? 'true' : 'false') . ') { + if (' . (ProxyHttp::isHttps() ? 'true' : 'false') . ') { return url.replace(/http:\/\//i, "https://"); } else { return url.replace(/https:\/\//i, "http://"); diff --git a/plugins/Proxy/Controller.php b/plugins/Proxy/Controller.php index 9378a6f3e1be2f35283bd4607805ef6cca36df04..0e514d692ec4539e2778310301d29a4aa1f8a9fc 100644 --- a/plugins/Proxy/Controller.php +++ b/plugins/Proxy/Controller.php @@ -13,7 +13,7 @@ namespace Piwik\Plugins\Proxy; use Piwik\AssetManager; use Piwik\Common; use Piwik\Piwik; -use Piwik\ProxyStaticFile; +use Piwik\ProxyHttp; use Piwik\Url; /** @@ -35,7 +35,7 @@ class Controller extends \Piwik\Controller public function getCss() { $cssMergedFile = AssetManager::getMergedCssFileLocation(); - ProxyStaticFile::serveFile($cssMergedFile, "text/css"); + ProxyHttp::serverStaticFile($cssMergedFile, "text/css"); } /** @@ -47,7 +47,7 @@ class Controller extends \Piwik\Controller public function getJs() { $jsMergedFile = AssetManager::getMergedJsFileLocation(); - ProxyStaticFile::serveFile($jsMergedFile, self::JS_MIME_TYPE); + ProxyHttp::serverStaticFile($jsMergedFile, self::JS_MIME_TYPE); } /** @@ -65,7 +65,7 @@ class Controller extends \Piwik\Controller AssetManager::removeTranslationsJsFile(); $translationsJsFile = AssetManager::getTranslationsJsFileLocation(); - ProxyStaticFile::serveFile($translationsJsFile, self::JS_MIME_TYPE); + ProxyHttp::serverStaticFile($translationsJsFile, self::JS_MIME_TYPE); } /** diff --git a/tests/PHPUnit/Core/ServeStaticFileTest.php b/tests/PHPUnit/Core/ServeStaticFileTest.php index a5cbaa1d393e7f2fdd97fd13056fcc27e8e93fdb..e6aeb2e5d92b58e71c97d3bc1fae729b61c738b2 100644 --- a/tests/PHPUnit/Core/ServeStaticFileTest.php +++ b/tests/PHPUnit/Core/ServeStaticFileTest.php @@ -1,20 +1,20 @@ <?php /** - * This php file is used to unit test Piwik::serveFile() + * This php file is used to unit test Piwik::serverStaticFile() * Unit tests for this method should normally be located in /tests/core/Piwik.test.php - * To make a comprehensive test suit for Piwik::serveFile() (ie. being able to test combinations of request + * To make a comprehensive test suit for Piwik::serverStaticFile() (ie. being able to test combinations of request * headers, being able to test response headers and so on) we need to simulate static file requests in a controlled * environment - * The php code which simulates requests using Piwik::serveFile() is provided in the same file (ie. this one) - * as the unit testing code for Piwik::serveFile() + * The php code which simulates requests using Piwik::serverStaticFile() is provided in the same file (ie. this one) + * as the unit testing code for Piwik::serverStaticFile() * This decision has a structural impact on the usual unit test file structure - * serveFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php + * serverStaticFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php */ // This is Piwik logo, the static file used in this test suit use Piwik\Common; use Piwik\Piwik; -use Piwik\ProxyStaticFile; +use Piwik\ProxyHttp; define("TEST_FILE_LOCATION", realpath(dirname(__FILE__) . "/../../resources/lipsum.txt")); define("TEST_FILE_CONTENT_TYPE", "text/plain"); @@ -26,7 +26,7 @@ define("ZLIB_OUTPUT_REQUEST_VAR", "zlibOutput"); /** * These constants define the mode in which this php file is used : - * - for unit testing Piwik::serveFile() or + * - for unit testing Piwik::serverStaticFile() or * - as a static file server */ define("STATIC_SERVER_MODE", "staticServerMode"); @@ -53,11 +53,11 @@ class Test_Piwik_ServeStaticFile extends PHPUnit_Framework_TestCase */ public function test_phpOutputCompression() { - $this->assertFalse(ProxyStaticFile::isPhpOutputCompressed()); + $this->assertFalse(ProxyHttp::isPhpOutputCompressed()); } /** - * Checks that "HTTP/1.0 404 Not Found" is returned when Piwik::serveFile is called with a null file + * Checks that "HTTP/1.0 404 Not Found" is returned when Piwik::serverStaticFile is called with a null file * * @group ServeStaticFile */ @@ -74,7 +74,8 @@ class Test_Piwik_ServeStaticFile extends PHPUnit_Framework_TestCase } /** - * Checks that "HTTP/1.0 404 Not Found" is returned when Piwik::serveFile is called with a non existing file + * Checks that "HTTP/1.0 404 Not Found" is returned when Piwik::serverStaticFile is called with a non existing file + * * * @group ServeStaticFile */ @@ -91,7 +92,7 @@ class Test_Piwik_ServeStaticFile extends PHPUnit_Framework_TestCase } /** - * Checks that "HTTP/1.0 505 Internal server error" is returned when Piwik::serveFile is called with a + * Checks that "HTTP/1.0 505 Internal server error" is returned when Piwik::serverStaticFile is called with a * non-readable file * * @group ServeStaticFile diff --git a/tests/resources/staticFileServer.php b/tests/resources/staticFileServer.php index 0646b6b3cc08eb459ce629c0df253e1089668f8c..cdaa54830f859ad4b25a0898e7362ae1cb040562 100644 --- a/tests/resources/staticFileServer.php +++ b/tests/resources/staticFileServer.php @@ -1,16 +1,16 @@ <?php /** - * This php file is used to unit test Piwik::serveFile() - * To make a comprehensive test suit for Piwik::serveFile() (ie. being able to test combinations of request + * This php file is used to unit test Piwik::serverStaticFile() + * To make a comprehensive test suit for Piwik::serverStaticFile() (ie. being able to test combinations of request * headers, being able to test response headers and so on) we need to simulate static file requests in a controlled * environment - * The php code which simulates requests using Piwik::serveFile() is provided in the same file (ie. this one) - * as the unit testing code for Piwik::serveFile() + * The php code which simulates requests using Piwik::serverStaticFile() is provided in the same file (ie. this one) + * as the unit testing code for Piwik::serverStaticFile() * This decision has a structural impact on the usual unit test file structure - * serveFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php + * serverStaticFile.test.php has been created to avoid making too many modifications to /tests/core/Piwik.test.php */ use Piwik\Common; -use Piwik\ProxyStaticFile; +use Piwik\ProxyHttp; define('PIWIK_DOCUMENT_ROOT', dirname(__FILE__).'/../../'); if(file_exists(PIWIK_DOCUMENT_ROOT . '/bootstrap.php')) @@ -58,7 +58,7 @@ define("TEST_FILE_SRV_MODE", "testFile"); /** * If the static file server has been requested, the response sent back to the browser will be the content produced by - * the execution of Piwik:serveFile(). In this case, unit tests won't be executed + * the execution of Piwik:serverStaticFile(). In this case, unit tests won't be executed */ // Getting the server mode $staticFileServerMode = Common::getRequestVar(SRV_MODE_REQUEST_VAR, ""); @@ -72,21 +72,21 @@ if ($staticFileServerMode === "") { } switch ($staticFileServerMode) { - // The static file server calls Piwik::serveFile with a null file + // The static file server calls Piwik::serverStaticFile with a null file case NULL_FILE_SRV_MODE: - ProxyStaticFile::serveFile(null, TEST_FILE_CONTENT_TYPE); + ProxyHttp::serverStaticFile(null, TEST_FILE_CONTENT_TYPE); break; - // The static file server calls Piwik::serveFile with a non-existing file + // The static file server calls Piwik::serverStaticFile with a non-existing file case GHOST_FILE_SRV_MODE: - ProxyStaticFile::serveFile(TEST_FILE_LOCATION . ".ghost", TEST_FILE_CONTENT_TYPE); + ProxyHttp::serverStaticFile(TEST_FILE_LOCATION . ".ghost", TEST_FILE_CONTENT_TYPE); break; - // The static file server calls Piwik::serveFile with the test file + // The static file server calls Piwik::serverStaticFile with the test file case TEST_FILE_SRV_MODE: - ProxyStaticFile::serveFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE); + ProxyHttp::serverStaticFile(TEST_FILE_LOCATION, TEST_FILE_CONTENT_TYPE); break; } \ No newline at end of file