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

Skip to content

[3.1][HttpKernel] Fix RequestDataCollector starting the session #18954

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

Merged
merged 1 commit into from
Jun 3, 2016
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function collect(Request $request, Response $response, \Exception $except
unset($this->controllers[$request]);
}

if (null !== $session) {
if (null !== $session && $session->isStarted()) {
if ($request->attributes->has('_redirected')) {
$this->data['redirect'] = $session->remove('sf_redirect');
}
Expand Down Expand Up @@ -291,7 +291,7 @@ public function onKernelController(FilterControllerEvent $event)

public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest() || !$event->getRequest()->hasSession()) {
if (!$event->isMasterRequest() || !$event->getRequest()->hasSession() || !$event->getRequest()->getSession()->isStarted()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

namespace Symfony\Component\HttpKernel\Tests\DataCollector;

use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
Expand Down Expand Up @@ -52,6 +55,20 @@ public function testCollect()
$this->assertSame('application/json', $c->getContentType());
}

public function testKernelResponseDoesNotStartSession()
{
$kernel = $this->getMock(HttpKernelInterface::class);
$request = new Request();
$session = new Session(new MockArraySessionStorage());
$request->setSession($session);
$response = new Response();

$c = new RequestDataCollector();
$c->onKernelResponse(new FilterResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST, $response));

$this->assertFalse($session->isStarted());
}

/**
* Test various types of controller callables.
*/
Expand Down