[WebProfilerBundle] Improved cookie traffic

This commit is contained in:
Roland Franssen 2016-12-17 20:00:53 +00:00
parent 5dcef29531
commit 171c6d100e
3 changed files with 39 additions and 13 deletions

View File

@ -143,16 +143,6 @@
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestattributes }, with_context = false) }}
{% endif %}
<h3>Cookies</h3>
{% if collector.requestcookies.all is empty %}
<div class="empty">
<p>No cookies</p>
</div>
{% else %}
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestcookies }, with_context = false) }}
{% endif %}
<h3>Request Headers</h3>
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestheaders, labels: ['Header', 'Value'], maxDepth: 1 }, with_context = false) }}
@ -187,6 +177,32 @@
</div>
</div>
<div class="tab {{ collector.requestcookies.all is empty and collector.responsecookies.all is empty ? 'disabled' }}">
<h3 class="tab-title">Cookies</h3>
<div class="tab-content">
<h3>Request Cookies</h3>
{% if collector.requestcookies.all is empty %}
<div class="empty">
<p>No request cookies</p>
</div>
{% else %}
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestcookies }, with_context = false) }}
{% endif %}
<h3>Response Cookies</h3>
{% if collector.responsecookies.all is empty %}
<div class="empty">
<p>No response cookies</p>
</div>
{% else %}
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.responsecookies }, with_context = true) }}
{% endif %}
</div>
</div>
<div class="tab {{ collector.sessionmetadata is empty ? 'disabled' }}">
<h3 class="tab-title">Session</h3>

View File

@ -76,6 +76,11 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
$statusCode = $response->getStatusCode();
$responseCookies = array();
foreach ($response->headers->getCookies() as $cookie) {
$responseCookies[$cookie->getName()] = $cookie;
}
$this->data = array(
'method' => $request->getMethod(),
'format' => $request->getRequestFormat(),
@ -91,6 +96,7 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
'request_attributes' => $attributes,
'route' => $route,
'response_headers' => $response->headers->all(),
'response_cookies' => $responseCookies,
'session_metadata' => $sessionMetadata,
'session_attributes' => $sessionAttributes,
'flashes' => $flashes,
@ -190,6 +196,11 @@ class RequestDataCollector extends DataCollector implements EventSubscriberInter
return new ParameterBag($this->data['response_headers']->getValue());
}
public function getResponseCookies()
{
return new ParameterBag($this->data['response_cookies']->getValue());
}
public function getSessionMetadata()
{
return $this->data['session_metadata']->getValue();

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Tests\DataCollector;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
@ -25,8 +26,6 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\VarDumper\Cloner\Data;
use Symfony\Component\VarDumper\Cloner\VarCloner;
class RequestDataCollectorTest extends TestCase
{
@ -36,7 +35,6 @@ class RequestDataCollectorTest extends TestCase
$c->collect($request = $this->createRequest(), $this->createResponse());
$cloner = new VarCloner();
$attributes = $c->getRequestAttributes();
$this->assertSame('request', $c->getName());
@ -46,6 +44,7 @@ class RequestDataCollectorTest extends TestCase
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $attributes);
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestRequest());
$this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag', $c->getRequestQuery());
$this->assertInstanceOf(ParameterBag::class, $c->getResponseCookies());
$this->assertSame('html', $c->getFormat());
$this->assertEquals('foobar', $c->getRoute());
$this->assertEquals(array('name' => 'foo'), $c->getRouteParams());