[HttpClient] Support for cURL handler objects.

This commit is contained in:
Alexander M. Turek 2020-06-22 14:59:33 +02:00 committed by Fabien Potencier
parent aeb0946df0
commit 7ccc2e1f28
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;