Skip to content

[HttpClient][WebProfilerBundle] Do not generate cURL command when files are uploaded #52472

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 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\HttpClient\DataCollector;

use Symfony\Component\HttpClient\Exception\TransportException;
use Symfony\Component\HttpClient\HttpClientTrait;
use Symfony\Component\HttpClient\TraceableHttpClient;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -199,7 +200,11 @@ private function getCurlCommand(array $trace): ?string
if (\is_string($body)) {
$dataArg[] = '--data-raw '.$this->escapePayload($body);
} elseif (\is_array($body)) {
$body = explode('&', self::normalizeBody($body));
try {
$body = explode('&', self::normalizeBody($body));
} catch (TransportException) {
return null;
}
foreach ($body as $value) {
$dataArg[] = '--data-raw '.$this->escapePayload(urldecode($value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@ public function testItIsEmptyAfterReset()
}

/**
* @requires extension openssl
*
* @dataProvider provideCurlRequests
*/
public function testItGeneratesCurlCommandsAsExpected(array $request, string $expectedCurlCommand)
Expand Down Expand Up @@ -342,9 +340,6 @@ public function __toString(): string
}
}

/**
* @requires extension openssl
*/
public function testItDoesNotFollowRedirectionsWhenGeneratingCurlCommands()
{
$sut = new HttpClientDataCollector();
Expand Down Expand Up @@ -372,9 +367,6 @@ public function testItDoesNotFollowRedirectionsWhenGeneratingCurlCommands()
);
}

/**
* @requires extension openssl
*/
public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType()
{
$sut = new HttpClientDataCollector();
Expand All @@ -394,9 +386,6 @@ public function testItDoesNotGeneratesCurlCommandsForUnsupportedBodyType()
self::assertNull($curlCommand);
}

/**
* @requires extension openssl
*/
public function testItDoesGenerateCurlCommandsForBigData()
{
$sut = new HttpClientDataCollector();
Expand All @@ -416,6 +405,25 @@ public function testItDoesGenerateCurlCommandsForBigData()
self::assertNotNull($curlCommand);
}

public function testItDoesNotGeneratesCurlCommandsForUploadedFiles()
{
$sut = new HttpClientDataCollector();
$sut->registerClient('http_client', $this->httpClientThatHasTracedRequests([
[
'method' => 'POST',
'url' => 'http://localhost:8057/json',
'options' => [
'body' => ['file' => fopen('data://text/plain,', 'r')],
],
],
]));
$sut->lateCollect();
$collectedData = $sut->getClients();
self::assertCount(1, $collectedData['http_client']['traces']);
$curlCommand = $collectedData['http_client']['traces'][0]['curlCommand'];
self::assertNull($curlCommand);
}

private function httpClientThatHasTracedRequests($tracedRequests): TraceableHttpClient
{
$httpClient = new TraceableHttpClient(new NativeHttpClient());
Expand Down