bug #37379 [HttpClient] Support for cURL handler objects (derrabus)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] Support for cURL handler objects

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

Commits
-------

7ccc2e1f28 [HttpClient] Support for cURL handler objects.
This commit is contained in:
Fabien Potencier 2020-06-24 10:43:43 +02:00
commit b3adba83fd
4 changed files with 7 additions and 5 deletions

View File

@ -337,7 +337,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface,
$this->multi->dnsCache->evictions = $this->multi->dnsCache->evictions ?: $this->multi->dnsCache->removals;
$this->multi->dnsCache->removals = $this->multi->dnsCache->hostnames = [];
if (\is_resource($this->multi->handle)) {
if (\is_resource($this->multi->handle) || $this->multi->handle instanceof \CurlMultiHandle) {
if (\defined('CURLMOPT_PUSHFUNCTION')) {
curl_multi_setopt($this->multi->handle, CURLMOPT_PUSHFUNCTION, null);
}
@ -347,7 +347,7 @@ final class CurlHttpClient implements HttpClientInterface, LoggerAwareInterface,
}
foreach ($this->multi->openHandles as [$ch]) {
if (\is_resource($ch)) {
if (\is_resource($ch) || $ch instanceof \CurlHandle) {
curl_setopt($ch, CURLOPT_VERBOSE, false);
}
}

View File

@ -20,7 +20,7 @@ namespace Symfony\Component\HttpClient\Internal;
*/
final class CurlClientState extends ClientState
{
/** @var resource */
/** @var \CurlMultiHandle|resource */
public $handle;
/** @var PushedResponse[] */
public $pushedResponses = [];

View File

@ -36,13 +36,15 @@ final class CurlResponse implements ResponseInterface
private $debugBuffer;
/**
* @param \CurlHandle|resource|string $ch
*
* @internal
*/
public function __construct(CurlClientState $multi, $ch, array $options = null, LoggerInterface $logger = null, string $method = 'GET', callable $resolveRedirect = null, int $curlVersion = null)
{
$this->multi = $multi;
if (\is_resource($ch)) {
if (\is_resource($ch) || $ch instanceof \CurlHandle) {
unset($multi->handlesActivity[(int) $ch]);
$this->handle = $ch;
$this->debugBuffer = fopen('php://temp', 'w+');

View File

@ -50,7 +50,7 @@ trait ResponseTrait
'canceled' => false,
];
/** @var resource */
/** @var object|resource */
private $handle;
private $id;
private $timeout = 0;