Skip to content

Commit 4503f94

Browse files
committed
[HttpClient][WebProfilerBundle] Do not generate cURL command when files are uploaded
1 parent 01efac5 commit 4503f94

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\HttpClient\DataCollector;
1313

14+
use Symfony\Component\HttpClient\Exception\TransportException;
1415
use Symfony\Component\HttpClient\HttpClientTrait;
1516
use Symfony\Component\HttpClient\TraceableHttpClient;
1617
use Symfony\Component\HttpFoundation\Request;
@@ -199,7 +200,11 @@ private function getCurlCommand(array $trace): ?string
199200
if (\is_string($body)) {
200201
$dataArg[] = '--data-raw '.$this->escapePayload($body);
201202
} elseif (\is_array($body)) {
202-
$body = explode('&', self::normalizeBody($body));
203+
try {
204+
$body = explode('&', self::normalizeBody($body));
205+
} catch (TransportException) {
206+
return null;
207+
}
203208
foreach ($body as $value) {
204209
$dataArg[] = '--data-raw '.$this->escapePayload(urldecode($value));
205210
}

src/Symfony/Component/HttpClient/Tests/DataCollector/HttpClientDataCollectorTest.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ public function testItIsEmptyAfterReset()
165165
}
166166

167167
/**
168-
* @requires extension openssl
169-
*
170168
* @dataProvider provideCurlRequests
171169
*/
172170
public function testItGeneratesCurlCommandsAsExpected(array $request, string $expectedCurlCommand)
@@ -342,9 +340,6 @@ public function __toString(): string
342340
}
343341
}
344342

345-
/**
346-
* @requires extension openssl
347-
*/
348343
public function testItDoesNotFollowRedirectionsWhenGeneratingCurlCommands()
349344
{
350345
$sut = new HttpClientDataCollector();
@@ -372,9 +367,6 @@ public function testItDoesNotFollowRedirectionsWhenGeneratingCurlCommands()
372367
);
373368
}
374369

375-
/**
376-
* @requires extension openssl
377-
*/
378370
public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType()
379371
{
380372
$sut = new HttpClientDataCollector();
@@ -394,9 +386,6 @@ public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType()
394386
self::assertNull($curlCommand);
395387
}
396388

397-
/**
398-
* @requires extension openssl
399-
*/
400389
public function testItDoesGenerateCurlCommandsForBigData()
401390
{
402391
$sut = new HttpClientDataCollector();
@@ -416,6 +405,25 @@ public function testItDoesGenerateCurlCommandsForBigData()
416405
self::assertNotNull($curlCommand);
417406
}
418407

408+
public function testItDoesNotGeneratesCurlCommandsForUploadedFiles()
409+
{
410+
$sut = new HttpClientDataCollector();
411+
$sut->registerClient('http_client', $this->httpClientThatHasTracedRequests([
412+
[
413+
'method' => 'POST',
414+
'url' => 'http://localhost:8057/json',
415+
'options' => [
416+
'body' => ['file' => fopen('data://text/plain,', 'r')],
417+
],
418+
],
419+
]));
420+
$sut->lateCollect();
421+
$collectedData = $sut->getClients();
422+
self::assertCount(1, $collectedData['http_client']['traces']);
423+
$curlCommand = $collectedData['http_client']['traces'][0]['curlCommand'];
424+
self::assertNull($curlCommand);
425+
}
426+
419427
private function httpClientThatHasTracedRequests($tracedRequests): TraceableHttpClient
420428
{
421429
$httpClient = new TraceableHttpClient(new NativeHttpClient());

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy