From f0b52c828936543fc4c3ed13cdfba8e2dd2f6e2d Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 18 Oct 2021 18:29:49 +0200 Subject: [PATCH] [HttpClient] fix collecting debug info on destruction of CurlResponse --- .../Component/HttpClient/Response/CurlResponse.php | 12 +++++++----- .../HttpClient/Tests/HttpClientTestCase.php | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index c0891321fe5a2..ae596ba7eefd1 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -225,13 +225,15 @@ public function getContent(bool $throw = true): string public function __destruct() { - curl_setopt($this->handle, \CURLOPT_VERBOSE, false); + try { + if (null === $this->timeout) { + return; // Unused pushed response + } - if (null === $this->timeout) { - return; // Unused pushed response + $this->doDestruct(); + } finally { + curl_setopt($this->handle, \CURLOPT_VERBOSE, false); } - - $this->doDestruct(); } /** diff --git a/src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php b/src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php index 85466d33b5438..36e76ee83b9a1 100644 --- a/src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php +++ b/src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php @@ -167,4 +167,16 @@ public function testHandleIsRemovedOnException() $this->assertCount(0, $clientState->openHandles); } } + + public function testDebugInfoOnDestruct() + { + $client = $this->getHttpClient(__FUNCTION__); + + $traceInfo = []; + $client->request('GET', 'http://localhost:8057', ['on_progress' => function (int $dlNow, int $dlSize, array $info) use (&$traceInfo) { + $traceInfo = $info; + }]); + + $this->assertNotEmpty($traceInfo['debug']); + } }