Skip to content

Commit

Permalink
bug #43569 [HttpClient] fix collecting debug info on destruction of C…
Browse files Browse the repository at this point in the history
…urlResponse (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] fix collecting debug info on destruction of CurlResponse

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #43348
| License       | MIT
| Doc PR        | -

Commits
-------

f0b52c8 [HttpClient] fix collecting debug info on destruction of CurlResponse
  • Loading branch information
fabpot committed Oct 18, 2021
2 parents 842b3f1 + f0b52c8 commit abb9a19
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Symfony/Component/HttpClient/Response/CurlResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Symfony/Component/HttpClient/Tests/HttpClientTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

0 comments on commit abb9a19

Please sign in to comment.