Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 89b6bb8

Browse filesBrowse files
committed
bug #18618 [HttpKernel] tweaked redirection profiling in RequestDataCollector (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
2 parents 90eee01 + df19c14 commit 89b6bb8
Copy full SHA for 89b6bb8

File tree

Expand file treeCollapse file tree

2 files changed

+30
-25
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+30
-25
lines changed

‎src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Added `Controller::json` to simplify creating JSON responses when using the Serializer component
88
* Deprecated absolute template paths support in the template name parser
99
* Deprecated using core form types without dependencies as services
10+
* Added `Symfony\Component\HttpHernel\DataCollector\RequestDataCollector::onKernelResponse()`
1011
* Added `Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector`
1112
* Deprecated service `serializer.mapping.cache.apc` (use `serializer.mapping.cache.doctrine.apc` instead)
1213

‎src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php
+29-25Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\HttpFoundation\Request;
1717
use Symfony\Component\HttpFoundation\Response;
1818
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
19+
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
1920
use Symfony\Component\HttpKernel\KernelEvents;
2021
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
2122
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@@ -128,33 +129,22 @@ public function collect(Request $request, Response $response, \Exception $except
128129
unset($this->controllers[$request]);
129130
}
130131

131-
if ($request->hasSession() && $request->getSession()->has('sf_redirect')) {
132-
$this->data['redirect'] = $request->getSession()->get('sf_redirect');
133-
$request->getSession()->remove('sf_redirect');
134-
}
135-
136-
if ($request->hasSession() && $response->isRedirect()) {
137-
$request->getSession()->set('sf_redirect', array(
138-
'token' => $response->headers->get('x-debug-token'),
139-
'route' => $request->attributes->get('_route', 'n/a'),
140-
'method' => $request->getMethod(),
141-
'controller' => $this->parseController($request->attributes->get('_controller')),
142-
'status_code' => $statusCode,
143-
'status_text' => Response::$statusTexts[(int) $statusCode],
144-
));
145-
}
132+
if (isset($session)) {
133+
if ($request->attributes->has('_redirected')) {
134+
$this->data['redirect'] = $session->remove('sf_redirect');
135+
}
146136

147-
if ($parentRequestAttributes = $request->attributes->get('_forwarded')) {
148-
if ($parentRequestAttributes instanceof ParameterBag) {
149-
$parentRequestAttributes->set('_forward_token', $response->headers->get('x-debug-token'));
137+
if ($response->isRedirect()) {
138+
$session->set('sf_redirect', array(
139+
'token' => $response->headers->get('x-debug-token'),
140+
'route' => $request->attributes->get('_route', 'n/a'),
141+
'method' => $request->getMethod(),
142+
'controller' => $this->parseController($request->attributes->get('_controller')),
143+
'status_code' => $statusCode,
144+
'status_text' => Response::$statusTexts[(int) $statusCode],
145+
));
150146
}
151147
}
152-
if ($request->attributes->has('_forward_controller')) {
153-
$this->data['forward'] = array(
154-
'token' => $request->attributes->get('_forward_token'),
155-
'controller' => $this->parseController($request->attributes->get('_forward_controller')),
156-
);
157-
}
158148
}
159149

160150
public function getMethod()
@@ -298,9 +288,23 @@ public function onKernelController(FilterControllerEvent $event)
298288
$this->controllers[$event->getRequest()] = $event->getController();
299289
}
300290

291+
public function onKernelResponse(FilterResponseEvent $event)
292+
{
293+
if (!$event->isMasterRequest() || !$event->getRequest()->hasSession()) {
294+
return;
295+
}
296+
297+
if ($event->getRequest()->getSession()->has('sf_redirect')) {
298+
$event->getRequest()->attributes->set('_redirected', true);
299+
}
300+
}
301+
301302
public static function getSubscribedEvents()
302303
{
303-
return array(KernelEvents::CONTROLLER => 'onKernelController');
304+
return array(
305+
KernelEvents::CONTROLLER => 'onKernelController',
306+
KernelEvents::RESPONSE => 'onKernelResponse',
307+
);
304308
}
305309

306310
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.