Merge pull request #1334 from thegallagher/2.3-cache-fix

Fix content-type header in cached views.

Fixes #2358
This commit is contained in:
Mark Story 2013-06-12 18:27:42 -07:00
commit e454f2d2a3
3 changed files with 6 additions and 3 deletions

View file

@ -60,6 +60,7 @@ class CacheDispatcher extends DispatcherFilter {
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();

View file

@ -307,7 +307,7 @@ class CacheHelper extends AppHelper {
$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)) . '\'));

View file

@ -547,10 +547,12 @@ class View extends Object {
* @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();
@ -564,7 +566,7 @@ class View extends Object {
return false;
} else {
if ($this->layout === 'xml') {
header('Content-type: text/xml');
$response->type('xml');
}
return substr($out, strlen($match[0]));
}