Skip to content

Commit 6a2721c

Browse files
authored
Merge pull request #421 from php-http/improve-no-body-message
tell user if body capturing was disabled
2 parents 551bd65 + 69c08ab commit 6a2721c

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
The change log describes what is "Added", "Removed", "Changed" or "Fixed" between each release.
44

5+
# unreleased
6+
7+
- If captured_body_length is set to 0 (default value), show a special message rather than the
8+
generic message `This message has no captured body`.
9+
510
# 1.27.0 - 2022-07-25
611

712
- Added support for configuring the error plugin via configuration

src/Collector/Collector.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
1010

1111
/**
12-
* The Collector hold profiled Stacks pushed by StackPlugin. It also have a list of configured clients.
13-
* All those data are used to display the HTTPlug panel in the Symfony profiler.
12+
* The Collector holds profiled Stacks pushed by the StackPlugin. It also has a list of the configured clients.
13+
* This data is used to display the HTTPlug panel in the Symfony profiler.
1414
*
1515
* The collector is not designed for execution in a threaded application and does not support plugins that execute an
1616
* other request before the current one is sent by the client.
@@ -26,9 +26,15 @@ class Collector extends DataCollector
2626
*/
2727
private $activeStack;
2828

29-
public function __construct()
29+
/**
30+
* @var int|null
31+
*/
32+
private $capturedBodyLength;
33+
34+
public function __construct(?int $capturedBodyLength = null)
3035
{
3136
$this->reset();
37+
$this->capturedBodyLength = $capturedBodyLength;
3238
}
3339

3440
/**
@@ -48,6 +54,11 @@ public function getName(): string
4854
return 'httplug';
4955
}
5056

57+
public function getCapturedBodyLength(): ?int
58+
{
59+
return $this->capturedBodyLength;
60+
}
61+
5162
/**
5263
* Mark the stack as active. If a stack was already active, use it as parent for our stack.
5364
*/

src/DependencyInjection/HttplugExtension.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public function load(array $configs, ContainerBuilder $container)
9494
->getDefinition('httplug.formatter.full_http_message')
9595
->addArgument($config['profiling']['captured_body_length'])
9696
;
97+
$container
98+
->getDefinition('httplug.collector.collector')
99+
->addArgument($config['profiling']['captured_body_length'])
100+
;
97101

98102
if (!class_exists(TwigEnvironment::class) && !class_exists(\Twig_Environment::class)) {
99103
$container->removeDefinition('httplug.collector.twig.http_message');

src/Resources/views/http_message.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{% set content = '' %}
33
{% set data = data|split("\n")|slice(1) %}
44
{% set xdebugTokenLink = data|filter(v => 'x-debug-token-link:' in v|lower)|first|split(': ')|last %}
5-
5+
{% set noContent = capturedBodyLength is same as(0) ? '(captured_body_length is set to 0, no body captured)' : '(This message has no captured body)' %}
66
<table>
77
<thead>
88
<tr>
@@ -33,4 +33,4 @@
3333
</tbody>
3434
</table>
3535

36-
<div class='httplug-http-body httplug-hidden'>{{ content ? content|httplug_markup_body : '(This message has no captured body)' }}</div>
36+
<div class='httplug-http-body httplug-hidden'>{{ content ? content|httplug_markup_body : noContent }}</div>

src/Resources/views/stack.html.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
</div>
4040
<div class="httplug-messages">
4141
<div class="httplug-message card">
42-
{{ include('@Httplug/http_message.html.twig', { data: stack.clientRequest, header: 'Request' }, with_context=false) }}
42+
{{ include('@Httplug/http_message.html.twig', { data: stack.clientRequest, capturedBodyLength: collector.capturedBodyLength, header: 'Request' }, with_context=false) }}
4343
</div>
4444
<div class="httplug-message card">
45-
{{ include('@Httplug/http_message.html.twig', { data: stack.clientResponse, header: 'Response' }, with_context=false) }}
45+
{{ include('@Httplug/http_message.html.twig', { data: stack.clientResponse, capturedBodyLength: collector.capturedBodyLength, header: 'Response' }, with_context=false) }}
4646
</div>
4747
</div>
4848
{% if stack.profiles %}
@@ -51,10 +51,10 @@
5151
<h3 class="httplug-plugin-name">{{ profile.plugin }}</h3>
5252
<div class="httplug-messages">
5353
<div class="httplug-message">
54-
{{ include('@Httplug/http_message.html.twig', { data: profile.request, header: 'Request' }, with_context=false) }}
54+
{{ include('@Httplug/http_message.html.twig', { data: profile.request, capturedBodyLength: collector.capturedBodyLength, header: 'Request' }, with_context=false) }}
5555
</div>
5656
<div class="httplug-message">
57-
{{ include('@Httplug/http_message.html.twig', { data: profile.response, header: 'Response' }, with_context=false) }}
57+
{{ include('@Httplug/http_message.html.twig', { data: profile.response, capturedBodyLength: collector.capturedBodyLength, header: 'Response' }, with_context=false) }}
5858
</div>
5959
</div>
6060
{% if not loop.last %}

tests/Functional/ProfilingTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ProfilingTest extends TestCase
4141

4242
public function setUp(): void
4343
{
44-
$this->collector = new Collector([]);
44+
$this->collector = new Collector();
4545
$this->formatter = new Formatter(new FullHttpMessageFormatter(), new CurlCommandFormatter());
4646
$this->stopwatch = new Stopwatch();
4747
}

tests/Resources/app/config/config_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
framework:
22
secret: php-http
33
test: ~
4+
http_method_override: false
45

56
httplug:
67
discovery:

0 commit comments

Comments
 (0)