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

Skip to content

[HttpKernel] Fix #10437: Catch exceptions when reloading a no-cache request #10502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ protected function lookup(Request $request, $catch = false)
if ($this->options['allow_reload'] && $request->isNoCache()) {
$this->record($request, 'reload');

return $this->fetch($request);
return $this->fetch($request, $catch);
}

try {
Expand Down
11 changes: 11 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,17 @@ public function testShouldCatchExceptions()
$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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function assertExceptionsAreNotCaught()
$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().');
Expand All @@ -122,6 +122,7 @@ public function request($method, $uri = '/', $server = array(), $cookies = array
$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);

Expand Down