Skip to content

Commit

Permalink
bug #52472 [HttpClient][WebProfilerBundle] Do not generate cURL comma…
Browse files Browse the repository at this point in the history
…nd when files are uploaded (MatTheCat)

This PR was merged into the 6.3 branch.

Discussion
----------

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

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #51366
| License       | MIT

I also removed ``@requires` extension openssl` annotations since that does not seem to be the case since #45729.

Failures in AppVeyor occur because double quotes are missing around `--data-raw` values. Possibly related to #52429.

Commits
-------

4503f94 [HttpClient][WebProfilerBundle] Do not generate cURL command when files are uploaded
  • Loading branch information
nicolas-grekas committed Nov 6, 2023
2 parents 01efac5 + 4503f94 commit b8bba36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
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
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

0 comments on commit b8bba36

Please sign in to comment.