Skip to content

Commit

Permalink
[profiler] show cookies in separated tab for each request
Browse files Browse the repository at this point in the history
  • Loading branch information
evaisse committed Jul 20, 2015
1 parent 5c8edb2 commit 36465c5
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 4 deletions.
18 changes: 17 additions & 1 deletion DataCollector/ProfilerDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ public function fetchRequestInfos(Request $request)

parse_str($data['queryString'], $data['query']);
$data['contentType'] = $request->headers->get('content-type');
$data['cookies'] = $request->cookies->all();
return $data;
}

Expand All @@ -249,7 +250,22 @@ public function fetchResponseInfos(Response $response)
$data['headers'] = explode("\r\n\r\n", (string)$response, 2)[0];
$data['headers'] = explode("\r\n", $data['headers']);
$data['contentType'] = $response->headers->get('content-type');
$data['cookies'] = $response->headers->getCookies();
$cookies = $response->headers->getCookies();

$data['cookies'] = [];

foreach ($cookies as $c) {
$data['cookies'][$c->getName()] = array(
"value" => $c->getValue(),
"domain" => $c->getDomain(),
"expires" => date('Y-m-d H:i:s', $c->getExpiresTime()),
"path" => $c->getPath(),
"secure" => $c->isSecure(),
"httpOnly" => $c->isHttpOnly(),
"cleared" => $c->isCleared(),
);
}

$data['statusPhrase'] = $data['headers'][0];

return $data;
Expand Down
9 changes: 7 additions & 2 deletions Resources/views/Collector/partials/call.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<a href="javascript://">Error</a>
</li>
{% endif %}
<li>
<a href="javascript://">Cookies</a>
</li>
<li>
<a href="javascript://">Raw</a>
</li>
Expand All @@ -47,10 +50,12 @@
{% include 'SimpleHttpBundle:Collector:partials/error.html.twig' with {'index':index, 'error': call.error} %}
</div>
{% endif %}
<div>
<div class="tab-content-cookies">
{% include 'SimpleHttpBundle:Collector:partials/cookies.html.twig' with {'request': call.request, 'response': call.response} %}
</div>
<div class="tab-content--raw">
{{ dump(call) }}
</div>

</div>

</div>
Expand Down
65 changes: 65 additions & 0 deletions Resources/views/Collector/partials/cookies.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{% macro display_array_recursive(array, separator = ', ', opening_char = '[', closing_char = ']') -%}
{{ opening_char }}
{%- for key, value in array -%}
{%- if value is iterable -%}
{{ key }} => {{ _self.display_array_recursive(value, separator, opening_char, closing_char) }}
{%- else -%}
{{ key }} => {{ value }}
{%- if not loop.last %}{{ separator }}{% endif -%}
{%- endif -%}
{%- endfor -%}
{{ closing_char }}
{%- endmacro %}


<h5>Request Cookies</h5>


<table>
<tbody>
{% for name, parameter in request.cookies %}
<tr>
<th valign="top">{{ name }}</th>
<td>
{% if parameter is iterable %}
{{ _self.display_array_recursive(parameter) }}
{% else %}
{{ parameter }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>


{% if response %}
<h5>Response Cookies</h5>

<table>
<tbody>
{% for name, parameter in response.cookies %}
<tr>
{% if parameter.cleared %}
<th valign="top" style="text-decoration: line-through">{{ name }}</th>
{% else %}
<th valign="top">{{ name }}</th>
{% endif %}
<td>
{% if not parameter.cleared %}
{{ parameter.value }}
<hr style="background: #DDD; border:none; height:1px;" />
{% endif %}
<div style="color:#888">
{% if parameter is iterable %}
{{ _self.display_array_recursive(parameter) }}
{% else %}
{{ parameter }}
{% endif %}
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
7 changes: 6 additions & 1 deletion Resources/views/Collector/profiler.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
<strong>HTTP</strong>

<span class="count">
<span>{{ collector.countRequests }}</span>
{% if collector.countErrors > 0 %}
<span style="background:orange">{{ collector.countRequests }} / {{ collector.countErrors }}</span>
{% else %}
<span>{{ collector.countRequests }}</span>
{% endif %}

{% if (collector.totalTime * 1000) < 1000 %}
<span>{{ '%0.0f'|format(collector.totalTime * 1000) }} ms</span>
{% else %}
Expand Down

0 comments on commit 36465c5

Please sign in to comment.