Intercept redirections only for HTML format
This commit is contained in:
parent
287da8d4c0
commit
418678823b
@ -87,7 +87,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
|
||||
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
|
||||
|
@ -58,7 +58,7 @@ class WebDebugToolbarListenerTest extends TestCase
|
||||
/**
|
||||
* @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');
|
||||
@ -71,6 +71,19 @@ class WebDebugToolbarListenerTest extends TestCase
|
||||
$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>');
|
||||
|
Reference in New Issue
Block a user