Skip to content

[Profiler] Use tabular design for HTTP request/headers #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
### Changed

- Fixed error handling. Now TypeErrors and other \Throwable are correctly handled by ProfileClient
- Use tabular design in profiler for HTTP request/response headers

### Deprecated

- `httplug.collector.twig.http_message` service
- `httplug_markup` Twig function

## 1.16.0 - 2019-06-05

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"symfony/stopwatch": "^3.4.20 || ^4.2.1",
"symfony/twig-bundle": "^3.4.20 || ^4.2.1",
"symfony/web-profiler-bundle": "^3.4.20 || ^4.2.1",
"twig/twig": "^1.36 || ^2.6"
"twig/twig": "^1.41 || ^2.10"
},
"suggest": {
"php-http/cache-plugin": "To configure clients that cache responses",
Expand Down
4 changes: 0 additions & 4 deletions src/Collector/ProfileClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,6 @@ private function collectResponseInformations(ResponseInterface $response, Stopwa
$stack->setDuration($event->getDuration());
$stack->setResponseCode($response->getStatusCode());
$stack->setClientResponse($this->formatter->formatResponse($response));
if ($response->hasHeader('X-Debug-Token-Link')) {
$stack->setDebugToken($response->getHeaderLine('X-Debug-Token'));
$stack->setDebugTokenLink($response->getHeaderLine('X-Debug-Token-Link'));
}
}

/**
Expand Down
42 changes: 0 additions & 42 deletions src/Collector/Stack.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ final class Stack
*/
private $responseCode;

/**
* @var string|null
*/
private $debugToken;

/**
* @var string|null
*/
private $debugTokenLink;

/**
* @var int
*/
Expand Down Expand Up @@ -287,38 +277,6 @@ public function setResponseCode($responseCode)
$this->responseCode = $responseCode;
}

/**
* @return string
*/
public function getDebugToken()
{
return $this->debugToken;
}

/**
* @param string $debugToken
*/
public function setDebugToken($debugToken)
{
$this->debugToken = $debugToken;
}

/**
* @return string
*/
public function getDebugTokenLink()
{
return $this->debugTokenLink;
}

/**
* @param string $debugTokenLink
*/
public function setDebugTokenLink($debugTokenLink)
{
$this->debugTokenLink = $debugTokenLink;
}

/**
* @return string
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Collector/Twig/HttpMessageMarkupExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function getFilters()
*/
public function markup($message)
{
@trigger_error('"httplug_markup" twig extension is deprecated since version 1.17 and will be removed in 2.0. Use "@Httplug/http_message.html.twig" template instead.', E_USER_DEPRECATED);

$safeMessage = htmlentities($message);
$parts = preg_split('|\\r?\\n\\r?\\n|', $safeMessage, 2);

Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/data-collector.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<service id="httplug.collector.twig.http_message" class="Http\HttplugBundle\Collector\Twig\HttpMessageMarkupExtension" public="false">
<tag name="twig.extension" />
<deprecated>The %service_id% service is deprecated since version 1.17 and will be removed in 2.0. Use "@Httplug/http_message.html.twig" template instead.</deprecated>
</service>

<!-- Discovered clients -->
Expand Down
29 changes: 29 additions & 0 deletions src/Resources/views/http_message.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% set hasReachedBody = false %}
{% set content = '' %}
{% set data = data|split("\n")|slice(1) %}
{% set xdebugTokenLink = data|filter(v => 'x-debug-token-link:' in v|lower)|first|split(': ')|last %}

<table>
<thead>
<tr>
<th scope="col" class="key" colspan="2">{{ header }}{% if xdebugTokenLink %} <span style="float:right"><a href="{{ xdebugTokenLink }}">Profile link</a></span>{% endif %}</th>
</tr>
</thead>
<tbody>
{% for row in data %}
{% if row is empty %}
{% set hasReachedBody = true %}
{% elseif hasReachedBody %}
{% set content = content ~ "\n" ~ row %}
{% else %}
{% set row = row|split(':') %}
<tr>
<th>{{ row[0] }}</th>
<td>{{ row|slice(1)|join(':')|trim }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>

<div class='httplug-http-body httplug-hidden'>{{ content|nl2br ?: '(This message has no captured body)' }}</div>
12 changes: 4 additions & 8 deletions src/Resources/views/stack.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@
</div>
<div class="httplug-messages">
<div class="httplug-message card">
<h4>Request</h4>
{{ stack.clientRequest|httplug_markup|nl2br }}
{% include '@Httplug/http_message.html.twig' with { data: stack.clientRequest, header: 'Request' } only %}
</div>
<div class="httplug-message card">
<h4>Response {% if stack.debugTokenLink %}<span class="label status-info"><a href="{{ stack.debugTokenLink }}">Debug Token: {{ stack.debugToken }}</a></span>{% endif %}</h4>
{{ stack.clientResponse|httplug_markup|nl2br }}
{% include '@Httplug/http_message.html.twig' with { data: stack.clientResponse, header: 'Response' } only %}
</div>
</div>
{% if stack.profiles %}
Expand All @@ -48,12 +46,10 @@
<h3 class="httplug-plugin-name">{{ profile.plugin }}</h3>
<div class="httplug-messages">
<div class="httplug-message">
<h4>Request</h4>
{{ profile.request|httplug_markup|nl2br }}
{% include '@Httplug/http_message.html.twig' with { data: profile.request, header: 'Request' } only %}
</div>
<div class="httplug-message">
<h4>Response</h4>
{{ profile.response|httplug_markup|nl2br }}
{% include '@Httplug/http_message.html.twig' with { data: profile.response, header: 'Response' } only %}
</div>
</div>
{% if not loop.last %}
Expand Down
3 changes: 3 additions & 0 deletions tests/Functional/ProfilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

class ProfilerTest extends WebTestCase
{
/**
* @group legacy
*/
public function testShowProfiler(): void
{
$client = static::createClient();
Expand Down
3 changes: 3 additions & 0 deletions tests/Functional/ServiceInstantiationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public function testHttpClientNoDebug(): void
$this->assertInstanceOf(HttpClient::class, $client);
}

/**
* @group legacy
*/
public function testDebugToolbar(): void
{
static::bootKernel(['debug' => true]);
Expand Down