Skip to content

Commit

Permalink
Fix content-type header in cached views. Fixes issue #2358
Browse files Browse the repository at this point in the history
  • Loading branch information
thegallagher committed Jun 6, 2013
1 parent a079ca3 commit 0eead76
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/Cake/Routing/Filter/CacheDispatcher.php
Expand Up @@ -60,6 +60,7 @@ public function beforeDispatch(CakeEvent $event) {
if (file_exists($filename)) {
$controller = null;
$view = new View($controller);
$view->response = $event->data['response'];
$result = $view->renderCache($filename, microtime(true));
if ($result !== false) {
$event->stopPropagation();
Expand Down
2 changes: 1 addition & 1 deletion lib/Cake/View/Helper/CacheHelper.php
Expand Up @@ -307,7 +307,7 @@ protected function _writeFile($content, $timestamp, $useCallbacks = false) {

$file .= '
$request = unserialize(base64_decode(\'' . base64_encode(serialize($this->request)) . '\'));
$response = new CakeResponse();
$response->type(\'' . $this->_View->response->type() . '\');
$controller = new ' . $this->_View->name . 'Controller($request, $response);
$controller->plugin = $this->plugin = \'' . $this->_View->plugin . '\';
$controller->helpers = $this->helpers = unserialize(base64_decode(\'' . base64_encode(serialize($this->_View->helpers)) . '\'));
Expand Down
7 changes: 3 additions & 4 deletions lib/Cake/View/View.php
Expand Up @@ -547,10 +547,12 @@ public function renderLayout($content, $layout = null) {
* @return boolean Success of rendering the cached file.
*/
public function renderCache($filename, $timeStart) {
$response = $this->response;
ob_start();
include ($filename);

if (Configure::read('debug') > 0 && $this->layout !== 'xml') {
$type = $response->mapType($response->type());
if (Configure::read('debug') > 0 && $type === 'html') {
echo "<!-- Cached Render Time: " . round(microtime(true) - $timeStart, 4) . "s -->";
}
$out = ob_get_clean();
Expand All @@ -563,9 +565,6 @@ public function renderCache($filename, $timeStart) {
unset($out);
return false;
} else {
if ($this->layout === 'xml') {
header('Content-type: text/xml');
}
return substr($out, strlen($match[0]));
}
}
Expand Down

0 comments on commit 0eead76

Please sign in to comment.