Skip to content

Commit

Permalink
bug #31213 [WebProfilerBundle] Intercept redirections only for HTML f…
Browse files Browse the repository at this point in the history
…ormat (javiereguiluz)

This PR was merged into the 3.4 branch.

Discussion
----------

[WebProfilerBundle] Intercept redirections only for HTML format

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #31168
| License       | MIT
| Doc PR        | -

This applies the solution proposed by @bpolaszek in #31168.

Commits
-------

4186788 Intercept redirections only for HTML format
  • Loading branch information
fabpot committed Apr 24, 2019
2 parents 287da8d + 4186788 commit d98f783
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Expand Up @@ -87,7 +87,7 @@ public function onKernelResponse(FilterResponseEvent $event)
return;
}

if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects) {
if ($response->headers->has('X-Debug-Token') && $response->isRedirect() && $this->interceptRedirects && 'html' === $request->getRequestFormat()) {
$session = $request->getSession();
if (null !== $session && $session->isStarted() && $session->getFlashBag() instanceof AutoExpireFlashBag) {
// keep current flashes for one more request if using AutoExpireFlashBag
Expand Down
Expand Up @@ -58,7 +58,7 @@ public function getInjectToolbarTests()
/**
* @dataProvider provideRedirects
*/
public function testRedirectionIsIntercepted($statusCode, $hasSession)
public function testHtmlRedirectionIsIntercepted($statusCode, $hasSession)
{
$response = new Response('Some content', $statusCode);
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
Expand All @@ -71,6 +71,19 @@ public function testRedirectionIsIntercepted($statusCode, $hasSession)
$this->assertEquals('Redirection', $response->getContent());
}

public function testNonHtmlRedirectionIsNotIntercepted()
{
$response = new Response('Some content', '301');
$response->headers->set('X-Debug-Token', 'xxxxxxxx');
$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(false, 'json', true), HttpKernelInterface::MASTER_REQUEST, $response);

$listener = new WebDebugToolbarListener($this->getTwigMock('Redirection'), true);
$listener->onKernelResponse($event);

$this->assertEquals(301, $response->getStatusCode());
$this->assertEquals('Some content', $response->getContent());
}

public function testToolbarIsInjected()
{
$response = new Response('<html><head></head><body></body></html>');
Expand Down

0 comments on commit d98f783

Please sign in to comment.