From 7ccc2e1f28e62acaaa27ab2d6bc44daa0ee67310 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Mon, 22 Jun 2020 14:59:33 +0200 Subject: [PATCH] [HttpClient] Support for cURL handler objects. --- src/Symfony/Component/HttpClient/CurlHttpClient.php | 4 ++-- src/Symfony/Component/HttpClient/Internal/CurlClientState.php | 2 +- src/Symfony/Component/HttpClient/Response/CurlResponse.php | 4 +++- src/Symfony/Component/HttpClient/Response/ResponseTrait.php | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/HttpClient/CurlHttpClient.php b/src/Symfony/Component/HttpClient/CurlHttpClient.php index 0fda8c604c..ae82703ec1 100644 --- a/src/Symfony/Component/HttpClient/CurlHttpClient.php +++ b/src/Symfony/Component/HttpClient/CurlHttpClient.php @@ -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); } } diff --git a/src/Symfony/Component/HttpClient/Internal/CurlClientState.php b/src/Symfony/Component/HttpClient/Internal/CurlClientState.php index 1c2e6c8eed..af2e6869b3 100644 --- a/src/Symfony/Component/HttpClient/Internal/CurlClientState.php +++ b/src/Symfony/Component/HttpClient/Internal/CurlClientState.php @@ -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 = []; diff --git a/src/Symfony/Component/HttpClient/Response/CurlResponse.php b/src/Symfony/Component/HttpClient/Response/CurlResponse.php index c356f86c78..2856e004db 100644 --- a/src/Symfony/Component/HttpClient/Response/CurlResponse.php +++ b/src/Symfony/Component/HttpClient/Response/CurlResponse.php @@ -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+'); diff --git a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php index 8d4fe59ae6..e5fb055693 100644 --- a/src/Symfony/Component/HttpClient/Response/ResponseTrait.php +++ b/src/Symfony/Component/HttpClient/Response/ResponseTrait.php @@ -50,7 +50,7 @@ trait ResponseTrait 'canceled' => false, ]; - /** @var resource */ + /** @var object|resource */ private $handle; private $id; private $timeout = 0;