Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 16434b5

Browse files
committed
bug #10502 [HttpKernel] Fix #10437: Catch exceptions when reloading a no-cache request (romainneutron)
This PR was merged into the 2.3 branch. Discussion ---------- [HttpKernel] Fix #10437: Catch exceptions when reloading a no-cache request | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #10437 | License | MIT Commits ------- 8e3a395 Fix #10437: Catch exceptions when reloading a no-cache request
2 parents 1a26d28 + 8e3a395 commit 16434b5

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ protected function lookup(Request $request, $catch = false)
308308
if ($this->options['allow_reload'] && $request->isNoCache()) {
309309
$this->record($request, 'reload');
310310

311-
return $this->fetch($request);
311+
return $this->fetch($request, $catch);
312312
}
313313

314314
try {

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,17 @@ public function testShouldCatchExceptions()
934934
$this->assertExceptionsAreCaught();
935935
}
936936

937+
public function testShouldCatchExceptionsWhenReloadingAndNoCacheRequest()
938+
{
939+
$this->catchExceptions();
940+
941+
$this->setNextResponse();
942+
$this->cacheConfig['allow_reload'] = true;
943+
$this->request('GET', '/', array(), array(), false, array('Pragma' => 'no-cache'));
944+
945+
$this->assertExceptionsAreCaught();
946+
}
947+
937948
public function testShouldNotCatchExceptions()
938949
{
939950
$this->catchExceptions(false);

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTestCase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function assertExceptionsAreNotCaught()
107107
$this->assertFalse($this->kernel->isCatchingExceptions());
108108
}
109109

110-
public function request($method, $uri = '/', $server = array(), $cookies = array(), $esi = false)
110+
public function request($method, $uri = '/', $server = array(), $cookies = array(), $esi = false, $headers = array())
111111
{
112112
if (null === $this->kernel) {
113113
throw new \LogicException('You must call setNextResponse() before calling request().');
@@ -122,6 +122,7 @@ public function request($method, $uri = '/', $server = array(), $cookies = array
122122
$this->esi = $esi ? new Esi() : null;
123123
$this->cache = new HttpCache($this->kernel, $this->store, $this->esi, $this->cacheConfig);
124124
$this->request = Request::create($uri, $method, array(), $cookies, array(), $server);
125+
$this->request->headers->add($headers);
125126

126127
$this->response = $this->cache->handle($this->request, HttpKernelInterface::MASTER_REQUEST, $this->catch);
127128

0 commit comments

Comments
 (0)