From 8a1c17ca753059264f7b85b6018d9b6e742525df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Tue, 19 Nov 2019 00:30:04 +0100 Subject: [PATCH] [Profiler] Use tabular design for HTTP request/headers --- CHANGELOG.md | 6 +++ composer.json | 2 +- src/Collector/ProfileClient.php | 4 -- src/Collector/Stack.php | 42 ------------------- .../Twig/HttpMessageMarkupExtension.php | 2 + src/Resources/config/data-collector.xml | 1 + src/Resources/views/http_message.html.twig | 29 +++++++++++++ src/Resources/views/stack.html.twig | 12 ++---- tests/Functional/ProfilerTest.php | 3 ++ tests/Functional/ServiceInstantiationTest.php | 3 ++ 10 files changed, 49 insertions(+), 55 deletions(-) create mode 100644 src/Resources/views/http_message.html.twig diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d09cf50..b72402ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index b3c59fd6..3639041f 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Collector/ProfileClient.php b/src/Collector/ProfileClient.php index 02e56a9d..318120ea 100644 --- a/src/Collector/ProfileClient.php +++ b/src/Collector/ProfileClient.php @@ -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')); - } } /** diff --git a/src/Collector/Stack.php b/src/Collector/Stack.php index a53c4308..755e9487 100644 --- a/src/Collector/Stack.php +++ b/src/Collector/Stack.php @@ -81,16 +81,6 @@ final class Stack */ private $responseCode; - /** - * @var string|null - */ - private $debugToken; - - /** - * @var string|null - */ - private $debugTokenLink; - /** * @var int */ @@ -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 */ diff --git a/src/Collector/Twig/HttpMessageMarkupExtension.php b/src/Collector/Twig/HttpMessageMarkupExtension.php index 71077f74..6101ca66 100644 --- a/src/Collector/Twig/HttpMessageMarkupExtension.php +++ b/src/Collector/Twig/HttpMessageMarkupExtension.php @@ -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); diff --git a/src/Resources/config/data-collector.xml b/src/Resources/config/data-collector.xml index dd3f3b85..70b3d81f 100644 --- a/src/Resources/config/data-collector.xml +++ b/src/Resources/config/data-collector.xml @@ -24,6 +24,7 @@ + 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. diff --git a/src/Resources/views/http_message.html.twig b/src/Resources/views/http_message.html.twig new file mode 100644 index 00000000..5ad84b12 --- /dev/null +++ b/src/Resources/views/http_message.html.twig @@ -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 %} + + + + + + + + + {% for row in data %} + {% if row is empty %} + {% set hasReachedBody = true %} + {% elseif hasReachedBody %} + {% set content = content ~ "\n" ~ row %} + {% else %} + {% set row = row|split(':') %} + + + + + {% endif %} + {% endfor %} + +
{{ header }}{% if xdebugTokenLink %} Profile link{% endif %}
{{ row[0] }}{{ row|slice(1)|join(':')|trim }}
+ +
{{ content|nl2br ?: '(This message has no captured body)' }}
diff --git a/src/Resources/views/stack.html.twig b/src/Resources/views/stack.html.twig index ffca04cb..a437fcb9 100644 --- a/src/Resources/views/stack.html.twig +++ b/src/Resources/views/stack.html.twig @@ -34,12 +34,10 @@
-

Request

- {{ stack.clientRequest|httplug_markup|nl2br }} + {% include '@Httplug/http_message.html.twig' with { data: stack.clientRequest, header: 'Request' } only %}
-

Response {% if stack.debugTokenLink %}Debug Token: {{ stack.debugToken }}{% endif %}

- {{ stack.clientResponse|httplug_markup|nl2br }} + {% include '@Httplug/http_message.html.twig' with { data: stack.clientResponse, header: 'Response' } only %}
{% if stack.profiles %} @@ -48,12 +46,10 @@

{{ profile.plugin }}

-

Request

- {{ profile.request|httplug_markup|nl2br }} + {% include '@Httplug/http_message.html.twig' with { data: profile.request, header: 'Request' } only %}
-

Response

- {{ profile.response|httplug_markup|nl2br }} + {% include '@Httplug/http_message.html.twig' with { data: profile.response, header: 'Response' } only %}
{% if not loop.last %} diff --git a/tests/Functional/ProfilerTest.php b/tests/Functional/ProfilerTest.php index 9cdb84e6..d07f0044 100644 --- a/tests/Functional/ProfilerTest.php +++ b/tests/Functional/ProfilerTest.php @@ -6,6 +6,9 @@ class ProfilerTest extends WebTestCase { + /** + * @group legacy + */ public function testShowProfiler(): void { $client = static::createClient(); diff --git a/tests/Functional/ServiceInstantiationTest.php b/tests/Functional/ServiceInstantiationTest.php index 14e53be7..eb104bc8 100644 --- a/tests/Functional/ServiceInstantiationTest.php +++ b/tests/Functional/ServiceInstantiationTest.php @@ -42,6 +42,9 @@ public function testHttpClientNoDebug(): void $this->assertInstanceOf(HttpClient::class, $client); } + /** + * @group legacy + */ public function testDebugToolbar(): void { static::bootKernel(['debug' => true]);