public function output($files, $cache_key) { header('Content-Type: ' . $this->contentType); OC_Response::enableCaching(); $etag = $this->generateETag($files); $cache_key .= '-' . $etag; $gzout = false; $cache = OC_Cache::getGlobalCache(); if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)) { OC_Response::setETagHeader($etag); $gzout = $cache->get($cache_key . '.gz'); } if (!$gzout) { $out = $this->minimizeFiles($files); $gzout = gzencode($out); $cache->set($cache_key . '.gz', $gzout); OC_Response::setETagHeader($etag); } if ($encoding = OC_Request::acceptGZip()) { header('Content-Encoding: ' . $encoding); $out = $gzout; } else { $out = gzdecode($gzout); } header('Content-Length: ' . strlen($out)); echo $out; }
/** * Enable response caching by sending correct HTTP headers * @param int $cache_time time to cache the response * >0 cache time in seconds * 0 and <0 enable default browser caching * null cache indefinitly */ public static function enableCaching($cache_time = null) { \OC_Response::enableCaching($cache_time); }
public function show() { if ($this->useOriginal) { $fp = @$this->view->fopen($this->path, 'rb'); $mtime = $this->view->filemtime($this->path); $size = $this->view->filesize($this->path); $mime = $this->view->getMimetype($this->path); } else { $fp = @fopen($this->path, 'rb'); $mtime = filemtime($this->path); $size = filesize($this->path); $mime = \OC_Helper::getMimetype($this->path); } if ($fp) { \OC_Response::enableCaching(); \OC_Response::setLastModifiedHeader($mtime); header('Content-Length: ' . $size); header('Content-Type: ' . $mime); fpassthru($fp); } else { \OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND); } }
/** * Generate JSON response for routing in javascript */ public static function JSRoutes() { $router = OC::getRouter(); $etag = $router->getCacheKey(); OC_Response::enableCaching(); OC_Response::setETagHeader($etag); $root = $router->getCollection('root'); $routes = array(); foreach ($root->all() as $name => $route) { $compiled_route = $route->compile(); $defaults = $route->getDefaults(); unset($defaults['action']); $routes[$name] = array('tokens' => $compiled_route->getTokens(), 'defaults' => $defaults); } OCP\JSON::success(array('data' => $routes)); }
public static function loadfile() { if (file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE)) { if (substr(OC::$REQUESTEDFILE, -3) == 'css') { $appswebroot = (string) OC::$APPSWEBROOT; $webroot = (string) OC::$WEBROOT; $filepath = OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE; header('Content-Type: text/css'); OC_Response::enableCaching(); OC_Response::setLastModifiedHeader(filemtime($filepath)); $cssfile = file_get_contents($filepath); $cssfile = str_replace('%appswebroot%', $appswebroot, $cssfile); $cssfile = str_replace('%webroot%', $webroot, $cssfile); OC_Response::setETagHeader(md5($cssfile)); header('Content-Length: ' . strlen($cssfile)); echo $cssfile; exit; } elseif (substr(OC::$REQUESTEDFILE, -3) == 'php') { require_once OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE; } } else { header('HTTP/1.0 404 Not Found'); exit; } }