Browse Source

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

Fix content-type header in cached views.

Fixes #2358
Mark Story 12 years ago
parent
commit
e454f2d2a3

+ 1 - 0
lib/Cake/Routing/Filter/CacheDispatcher.php

@@ -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();

+ 1 - 1
lib/Cake/View/Helper/CacheHelper.php

@@ -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)) . '\'));

+ 4 - 2
lib/Cake/View/View.php

@@ -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]));
 			}