Skip to content

Commit

Permalink
bug #18562 [2.7][WebProfilerBunde] Give an absolute url in case the r…
Browse files Browse the repository at this point in the history
…equest occured from another domain (romainneutron)

This PR was merged into the 2.7 branch.

Discussion
----------

[2.7][WebProfilerBunde] Give an absolute url in case the request occured from another domain

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

This is related to #18413:

Using two symfony application ProjectA and MicroServiceB, if ProjectA issues XHR to MicroServiceB and both have the WebProfilerBundle enabled, then Ajax requests will be monitored in ProjectA. But - at the moment - it will try to look for profiles under ProjectA domain whereas data are stored on MicroServiceB domain.

This PR fixes this issue

Commits
-------

1a5d4ad [WebProfilerBunde] Give an absolute url in case the request occured from another domain
  • Loading branch information
fabpot committed Apr 21, 2016
2 parents 1ff12d9 + 1a5d4ad commit 70b12a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Expand Up @@ -65,7 +65,7 @@ public function onKernelResponse(FilterResponseEvent $event)
try {
$response->headers->set(
'X-Debug-Token-Link',
$this->urlGenerator->generate('_profiler', array('token' => $response->headers->get('X-Debug-Token')))
$this->urlGenerator->generate('_profiler', array('token' => $response->headers->get('X-Debug-Token')), UrlGeneratorInterface::ABSOLUTE_URL)
);
} catch (\Exception $e) {
$response->headers->set('X-Debug-Error', get_class($e).': '.$e->getMessage());
Expand Down
Expand Up @@ -16,6 +16,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class WebDebugToolbarListenerTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -195,16 +196,16 @@ public function testXDebugUrlHeader()
$urlGenerator
->expects($this->once())
->method('generate')
->with('_profiler', array('token' => 'xxxxxxxx'))
->will($this->returnValue('/_profiler/xxxxxxxx'))
->with('_profiler', array('token' => 'xxxxxxxx'), UrlGeneratorInterface::ABSOLUTE_URL)
->will($this->returnValue('http://mydomain.com/_profiler/xxxxxxxx'))
;

$event = new FilterResponseEvent($this->getKernelMock(), $this->getRequestMock(), HttpKernelInterface::MASTER_REQUEST, $response);

$listener = new WebDebugToolbarListener($this->getTwigMock(), false, WebDebugToolbarListener::ENABLED, 'bottom', $urlGenerator);
$listener->onKernelResponse($event);

$this->assertEquals('/_profiler/xxxxxxxx', $response->headers->get('X-Debug-Token-Link'));
$this->assertEquals('http://mydomain.com/_profiler/xxxxxxxx', $response->headers->get('X-Debug-Token-Link'));
}

public function testThrowingUrlGenerator()
Expand Down

0 comments on commit 70b12a8

Please sign in to comment.