Skip to content

Commit ec2bcc6

Browse files
committed
fix(review): Nicolas Grekas
1 parent 82b9907 commit ec2bcc6

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
8.1
5+
---
6+
7+
* Add cURL copy paste button in the Request/Response tab
8+
49
8.0
510
---
611

@@ -12,7 +17,6 @@ CHANGELOG
1217
* Add support for the `QUERY` HTTP method in the profiler
1318
* Add support for Server-Sent Events / `EventSource` requests in the debug toolbar
1419
* Add support for displaying the application runner class
15-
* Add cURL copy paste button in the Request/Response tab
1620

1721
7.3
1822
---

src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/request.html.twig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,6 @@
239239
<button class="btn btn-sm hidden" title="Copy as cURL" data-clipboard-text="{{ collector.curlCommand }}">Copy as cURL</button>
240240
<pre class="break-long-words">{{ collector.curlCommand }}</pre>
241241
</div>
242-
{% else %}
243-
<div class="empty">
244-
<p>No content</p>
245-
</div>
246242
{% endif %}
247243
</div>
248244
</div>

src/Symfony/Component/HttpKernel/DataCollector/RequestDataCollector.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -503,34 +503,28 @@ private function computeCurlCommand(Request $request): ?string
503503
{
504504
$command = ['curl', '--compressed'];
505505

506-
// Build the full URL
507506
$scheme = $request->isSecure() ? 'https' : 'http';
508507
$host = $request->server->get('HTTP_HOST', $request->server->get('SERVER_NAME', 'localhost'));
509508
$url = $scheme.'://'.$host.$request->getRequestUri();
510509

511-
if (!empty($request->query->all())) {
510+
if ($request->query->all()) {
512511
$url .= '?'.http_build_query($request->query->all());
513512
}
514513

515514
// Add HTTP method
516515
$method = $request->getMethod();
517-
switch ($method) {
518-
case Request::METHOD_HEAD:
519-
$command[] = '--head';
520-
break;
521-
case Request::METHOD_GET:
522-
break;
523-
default:
524-
$command[] = \sprintf('--request %s', $method);
516+
517+
if ($method === Request::METHOD_HEAD) {
518+
$command[] = '--head';
519+
} elseif ($method !== Request::METHOD_GET) {
520+
$command[] = '--request '.$method;
525521
}
526522

527523
$command[] = \sprintf('--url %s', escapeshellarg($url));
528524

529525
// Add headers
530526
foreach ($request->headers->all() as $name => $value) {
531-
if (\is_array($value)) {
532-
$value = implode(', ', $value);
533-
}
527+
$value = implode(', ', $value ?? []);
534528

535529
// Skip certain headers
536530
if (\in_array(strtolower($name), ['host', 'cookie'])) {
@@ -541,7 +535,7 @@ private function computeCurlCommand(Request $request): ?string
541535
}
542536

543537
// Add cookies
544-
if (!empty($request->cookies->all())) {
538+
if ($request->cookies->all()) {
545539
$cookies = [];
546540
foreach ($request->cookies->all() as $name => $value) {
547541
$cookies[] = $name.'='.$value;
@@ -551,7 +545,7 @@ private function computeCurlCommand(Request $request): ?string
551545

552546
// Add body data
553547
$content = $this->data['content'];
554-
if (!empty($content) && \in_array($method, [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH, Request::METHOD_DELETE])) {
548+
if ($content && \in_array($method, [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH, Request::METHOD_DELETE])) {
555549
$command[] = '--data-raw '.$this->escapePayload($content);
556550
}
557551

0 commit comments

Comments
 (0)