Skip to content

Commit

Permalink
bug #18618 [HttpKernel] tweaked redirection profiling in RequestDataC…
Browse files Browse the repository at this point in the history
…ollector (HeahDude)

This PR was merged into the 3.1-dev branch.

Discussion
----------

[HttpKernel] tweaked redirection profiling in RequestDataCollector

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | ~
| License       | MIT
| Doc PR        | ~

- c8ba3b2 removes duplicated code forgotten in #17589

- a47d2e8 fixes the collecting of redirect data in first sub request instead of redirected master request.

Commits
-------

df19c14 use a request attribute flag for redirection profile
b26cb6d [HttpKernel] added RequestDataCollector::onKernelResponse()
c8ba3b2 [HttpKernel] remove legacy duplicated code
  • Loading branch information
fabpot committed Apr 28, 2016
2 parents 90eee01 + df19c14 commit 89b6bb8
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* Added `Controller::json` to simplify creating JSON responses when using the Serializer component
* Deprecated absolute template paths support in the template name parser
* Deprecated using core form types without dependencies as services
* Added `Symfony\Component\HttpHernel\DataCollector\RequestDataCollector::onKernelResponse()`
* Added `Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector`
* Deprecated service `serializer.mapping.cache.apc` (use `serializer.mapping.cache.doctrine.apc` instead)

Expand Down
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down Expand Up @@ -128,33 +129,22 @@ public function collect(Request $request, Response $response, \Exception $except
unset($this->controllers[$request]);
}

if ($request->hasSession() && $request->getSession()->has('sf_redirect')) {
$this->data['redirect'] = $request->getSession()->get('sf_redirect');
$request->getSession()->remove('sf_redirect');
}

if ($request->hasSession() && $response->isRedirect()) {
$request->getSession()->set('sf_redirect', array(
'token' => $response->headers->get('x-debug-token'),
'route' => $request->attributes->get('_route', 'n/a'),
'method' => $request->getMethod(),
'controller' => $this->parseController($request->attributes->get('_controller')),
'status_code' => $statusCode,
'status_text' => Response::$statusTexts[(int) $statusCode],
));
}
if (isset($session)) {
if ($request->attributes->has('_redirected')) {
$this->data['redirect'] = $session->remove('sf_redirect');
}

if ($parentRequestAttributes = $request->attributes->get('_forwarded')) {
if ($parentRequestAttributes instanceof ParameterBag) {
$parentRequestAttributes->set('_forward_token', $response->headers->get('x-debug-token'));
if ($response->isRedirect()) {
$session->set('sf_redirect', array(
'token' => $response->headers->get('x-debug-token'),
'route' => $request->attributes->get('_route', 'n/a'),
'method' => $request->getMethod(),
'controller' => $this->parseController($request->attributes->get('_controller')),
'status_code' => $statusCode,
'status_text' => Response::$statusTexts[(int) $statusCode],
));
}
}
if ($request->attributes->has('_forward_controller')) {
$this->data['forward'] = array(
'token' => $request->attributes->get('_forward_token'),
'controller' => $this->parseController($request->attributes->get('_forward_controller')),
);
}
}

public function getMethod()
Expand Down Expand Up @@ -298,9 +288,23 @@ public function onKernelController(FilterControllerEvent $event)
$this->controllers[$event->getRequest()] = $event->getController();
}

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

if ($event->getRequest()->getSession()->has('sf_redirect')) {
$event->getRequest()->attributes->set('_redirected', true);
}
}

public static function getSubscribedEvents()
{
return array(KernelEvents::CONTROLLER => 'onKernelController');
return array(
KernelEvents::CONTROLLER => 'onKernelController',
KernelEvents::RESPONSE => 'onKernelResponse',
);
}

/**
Expand Down

0 comments on commit 89b6bb8

Please sign in to comment.