From 8e3a3951e34a582a33331c10876f171f2cba8fdf Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 20 Mar 2014 14:55:59 +0100 Subject: [PATCH] Fix #10437: Catch exceptions when reloading a no-cache request --- .../Component/HttpKernel/HttpCache/HttpCache.php | 2 +- .../HttpKernel/Tests/HttpCache/HttpCacheTest.php | 11 +++++++++++ .../HttpKernel/Tests/HttpCache/HttpCacheTestCase.php | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php index 1742980bfb..7cb6343699 100644 --- a/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php +++ b/src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php @@ -308,7 +308,7 @@ class HttpCache implements HttpKernelInterface, TerminableInterface if ($this->options['allow_reload'] && $request->isNoCache()) { $this->record($request, 'reload'); - return $this->fetch($request); + return $this->fetch($request, $catch); } try { diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php index a8064b832b..50a1de907d 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php @@ -934,6 +934,17 @@ class HttpCacheTest extends HttpCacheTestCase $this->assertExceptionsAreCaught(); } + public function testShouldCatchExceptionsWhenReloadingAndNoCacheRequest() + { + $this->catchExceptions(); + + $this->setNextResponse(); + $this->cacheConfig['allow_reload'] = true; + $this->request('GET', '/', array(), array(), false, array('Pragma' => 'no-cache')); + + $this->assertExceptionsAreCaught(); + } + public function testShouldNotCatchExceptions() { $this->catchExceptions(false); diff --git a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php index 4377f61fbe..586b8a7027 100644 --- a/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php +++ b/src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php @@ -107,7 +107,7 @@ class HttpCacheTestCase extends \PHPUnit_Framework_TestCase $this->assertFalse($this->kernel->isCatchingExceptions()); } - public function request($method, $uri = '/', $server = array(), $cookies = array(), $esi = false) + public function request($method, $uri = '/', $server = array(), $cookies = array(), $esi = false, $headers = array()) { if (null === $this->kernel) { throw new \LogicException('You must call setNextResponse() before calling request().'); @@ -122,6 +122,7 @@ class HttpCacheTestCase extends \PHPUnit_Framework_TestCase $this->esi = $esi ? new Esi() : null; $this->cache = new HttpCache($this->kernel, $this->store, $this->esi, $this->cacheConfig); $this->request = Request::create($uri, $method, array(), $cookies, array(), $server); + $this->request->headers->add($headers); $this->response = $this->cache->handle($this->request, HttpKernelInterface::MASTER_REQUEST, $this->catch);