diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index e35132d41cccc..69b2662fd1252 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -126,9 +126,14 @@ public function __construct( curl_setopt($ch, \CURLOPT_NOPROGRESS, false); curl_setopt($ch, \CURLOPT_PROGRESSFUNCTION, static function ($ch, $dlSize, $dlNow) use ($onProgress, &$info, $url, $multi, $debugBuffer) { try { + $info['debug'] ??= ''; rewind($debugBuffer); - $debug = ['debug' => stream_get_contents($debugBuffer)]; - $onProgress($dlNow, $dlSize, $url + curl_getinfo($ch) + $info + $debug); + if (fstat($debugBuffer)['size']) { + $info['debug'] .= stream_get_contents($debugBuffer); + rewind($debugBuffer); + ftruncate($debugBuffer, 0); + } + $onProgress($dlNow, $dlSize, $url + curl_getinfo($ch) + $info); } catch (\Throwable $e) { $multi->handlesActivity[(int) $ch][] = null; $multi->handlesActivity[(int) $ch][] = $e; @@ -209,14 +214,17 @@ public function getInfo(?string $type = null): mixed $info['starttransfer_time'] = 0.0; } + $info['debug'] ??= ''; rewind($this->debugBuffer); - $info['debug'] = stream_get_contents($this->debugBuffer); + if (fstat($this->debugBuffer)['size']) { + $info['debug'] .= stream_get_contents($this->debugBuffer); + rewind($this->debugBuffer); + ftruncate($this->debugBuffer, 0); + } $waitFor = curl_getinfo($this->handle, \CURLINFO_PRIVATE); if ('H' !== $waitFor[0] && 'C' !== $waitFor[0]) { curl_setopt($this->handle, \CURLOPT_VERBOSE, false); - rewind($this->debugBuffer); - ftruncate($this->debugBuffer, 0); $this->finalInfo = $info; } } diff --git a/src/Symfony/Component/HttpClient/TraceableHttpClient.php b/src/Symfony/Component/HttpClient/TraceableHttpClient.php index 83342db58f470..02acd61d136a5 100644 --- a/src/Symfony/Component/HttpClient/TraceableHttpClient.php +++ b/src/Symfony/Component/HttpClient/TraceableHttpClient.php @@ -39,7 +39,7 @@ public function request(string $method, string $url, array $options = []): Respo { $content = null; $traceInfo = []; - $this->tracedRequests[] = [ + $tracedRequest = [ 'method' => $method, 'url' => $url, 'options' => $options, @@ -51,7 +51,9 @@ public function request(string $method, string $url, array $options = []): Respo if (false === ($options['extra']['trace_content'] ?? true)) { unset($content); $content = false; + unset($tracedRequest['options']['body'], $tracedRequest['options']['json']); } + $this->tracedRequests[] = $tracedRequest; $options['on_progress'] = function (int $dlNow, int $dlSize, array $info) use (&$traceInfo, $onProgress) { $traceInfo = $info;