vendor/symfony/http-client/CurlHttpClient.php line 94

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\HttpClient;
  11. use Psr\Log\LoggerAwareInterface;
  12. use Psr\Log\LoggerInterface;
  13. use Symfony\Component\HttpClient\Exception\InvalidArgumentException;
  14. use Symfony\Component\HttpClient\Exception\TransportException;
  15. use Symfony\Component\HttpClient\Internal\CurlClientState;
  16. use Symfony\Component\HttpClient\Internal\PushedResponse;
  17. use Symfony\Component\HttpClient\Response\CurlResponse;
  18. use Symfony\Component\HttpClient\Response\ResponseStream;
  19. use Symfony\Contracts\HttpClient\HttpClientInterface;
  20. use Symfony\Contracts\HttpClient\ResponseInterface;
  21. use Symfony\Contracts\HttpClient\ResponseStreamInterface;
  22. use Symfony\Contracts\Service\ResetInterface;
  23. /**
  24.  * A performant implementation of the HttpClientInterface contracts based on the curl extension.
  25.  *
  26.  * This provides fully concurrent HTTP requests, with transparent
  27.  * HTTP/2 push when a curl version that supports it is installed.
  28.  *
  29.  * @author Nicolas Grekas <p@tchwork.com>
  30.  */
  31. final class CurlHttpClient implements HttpClientInterfaceLoggerAwareInterfaceResetInterface
  32. {
  33.     use HttpClientTrait;
  34.     private $defaultOptions self::OPTIONS_DEFAULTS + [
  35.         'auth_ntlm' => null// array|string - an array containing the username as first value, and optionally the
  36.                              //   password as the second one; or string like username:password - enabling NTLM auth
  37.         'extra' => [
  38.             'curl' => [],    // A list of extra curl options indexed by their corresponding CURLOPT_*
  39.         ],
  40.     ];
  41.     private static $emptyDefaults self::OPTIONS_DEFAULTS + ['auth_ntlm' => null];
  42.     /**
  43.      * @var LoggerInterface|null
  44.      */
  45.     private $logger;
  46.     /**
  47.      * An internal object to share state between the client and its responses.
  48.      *
  49.      * @var CurlClientState
  50.      */
  51.     private $multi;
  52.     /**
  53.      * @param array $defaultOptions     Default request's options
  54.      * @param int   $maxHostConnections The maximum number of connections to a single host
  55.      * @param int   $maxPendingPushes   The maximum number of pushed responses to accept in the queue
  56.      *
  57.      * @see HttpClientInterface::OPTIONS_DEFAULTS for available options
  58.      */
  59.     public function __construct(array $defaultOptions = [], int $maxHostConnections 6int $maxPendingPushes 50)
  60.     {
  61.         if (!\extension_loaded('curl')) {
  62.             throw new \LogicException('You cannot use the "Symfony\Component\HttpClient\CurlHttpClient" as the "curl" extension is not installed.');
  63.         }
  64.         $this->defaultOptions['buffer'] = $this->defaultOptions['buffer'] ?? \Closure::fromCallable([__CLASS__'shouldBuffer']);
  65.         if ($defaultOptions) {
  66.             [, $this->defaultOptions] = self::prepareRequest(nullnull$defaultOptions$this->defaultOptions);
  67.         }
  68.         $this->multi = new CurlClientState($maxHostConnections$maxPendingPushes);
  69.     }
  70.     public function setLogger(LoggerInterface $logger): void
  71.     {
  72.         $this->logger $this->multi->logger $logger;
  73.     }
  74.     /**
  75.      * @see HttpClientInterface::OPTIONS_DEFAULTS for available options
  76.      *
  77.      * {@inheritdoc}
  78.      */
  79.     public function request(string $methodstring $url, array $options = []): ResponseInterface
  80.     {
  81.         [$url$options] = self::prepareRequest($method$url$options$this->defaultOptions);
  82.         $scheme $url['scheme'];
  83.         $authority $url['authority'];
  84.         $host parse_url($authority\PHP_URL_HOST);
  85.         $proxy $options['proxy']
  86.             ?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null null)
  87.             // Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
  88.             ?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli''phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null;
  89.         $url implode(''$url);
  90.         if (!isset($options['normalized_headers']['user-agent'])) {
  91.             $options['headers'][] = 'User-Agent: Symfony HttpClient/Curl';
  92.         }
  93.         $curlopts = [
  94.             \CURLOPT_URL => $url,
  95.             \CURLOPT_TCP_NODELAY => true,
  96.             \CURLOPT_PROTOCOLS => \CURLPROTO_HTTP \CURLPROTO_HTTPS,
  97.             \CURLOPT_REDIR_PROTOCOLS => \CURLPROTO_HTTP \CURLPROTO_HTTPS,
  98.             \CURLOPT_FOLLOWLOCATION => true,
  99.             \CURLOPT_MAXREDIRS => $options['max_redirects'] ? $options['max_redirects'] : 0,
  100.             \CURLOPT_COOKIEFILE => ''// Keep track of cookies during redirects
  101.             \CURLOPT_TIMEOUT => 0,
  102.             \CURLOPT_PROXY => $proxy,
  103.             \CURLOPT_NOPROXY => $options['no_proxy'] ?? $_SERVER['no_proxy'] ?? $_SERVER['NO_PROXY'] ?? '',
  104.             \CURLOPT_SSL_VERIFYPEER => $options['verify_peer'],
  105.             \CURLOPT_SSL_VERIFYHOST => $options['verify_host'] ? 0,
  106.             \CURLOPT_CAINFO => $options['cafile'],
  107.             \CURLOPT_CAPATH => $options['capath'],
  108.             \CURLOPT_SSL_CIPHER_LIST => $options['ciphers'],
  109.             \CURLOPT_SSLCERT => $options['local_cert'],
  110.             \CURLOPT_SSLKEY => $options['local_pk'],
  111.             \CURLOPT_KEYPASSWD => $options['passphrase'],
  112.             \CURLOPT_CERTINFO => $options['capture_peer_cert_chain'],
  113.         ];
  114.         if (1.0 === (float) $options['http_version']) {
  115.             $curlopts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_1_0;
  116.         } elseif (1.1 === (float) $options['http_version']) {
  117.             $curlopts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_1_1;
  118.         } elseif (\defined('CURL_VERSION_HTTP2') && (\CURL_VERSION_HTTP2 CurlClientState::$curlVersion['features']) && ('https:' === $scheme || 2.0 === (float) $options['http_version'])) {
  119.             $curlopts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_2_0;
  120.         }
  121.         if (isset($options['auth_ntlm'])) {
  122.             $curlopts[\CURLOPT_HTTPAUTH] = \CURLAUTH_NTLM;
  123.             $curlopts[\CURLOPT_HTTP_VERSION] = \CURL_HTTP_VERSION_1_1;
  124.             if (\is_array($options['auth_ntlm'])) {
  125.                 $count \count($options['auth_ntlm']);
  126.                 if ($count <= || $count 2) {
  127.                     throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must contain 1 or 2 elements, %d given.'$count));
  128.                 }
  129.                 $options['auth_ntlm'] = implode(':'$options['auth_ntlm']);
  130.             }
  131.             if (!\is_string($options['auth_ntlm'])) {
  132.                 throw new InvalidArgumentException(sprintf('Option "auth_ntlm" must be a string or an array, "%s" given.'get_debug_type($options['auth_ntlm'])));
  133.             }
  134.             $curlopts[\CURLOPT_USERPWD] = $options['auth_ntlm'];
  135.         }
  136.         if (!\ZEND_THREAD_SAFE) {
  137.             $curlopts[\CURLOPT_DNS_USE_GLOBAL_CACHE] = false;
  138.         }
  139.         if (\defined('CURLOPT_HEADEROPT') && \defined('CURLHEADER_SEPARATE')) {
  140.             $curlopts[\CURLOPT_HEADEROPT] = \CURLHEADER_SEPARATE;
  141.         }
  142.         // curl's resolve feature varies by host:port but ours varies by host only, let's handle this with our own DNS map
  143.         if (isset($this->multi->dnsCache->hostnames[$host])) {
  144.             $options['resolve'] += [$host => $this->multi->dnsCache->hostnames[$host]];
  145.         }
  146.         if ($options['resolve'] || $this->multi->dnsCache->evictions) {
  147.             // First reset any old DNS cache entries then add the new ones
  148.             $resolve $this->multi->dnsCache->evictions;
  149.             $this->multi->dnsCache->evictions = [];
  150.             $port parse_url($authority\PHP_URL_PORT) ?: ('http:' === $scheme 80 443);
  151.             if ($resolve && 0x072A00 CurlClientState::$curlVersion['version_number']) {
  152.                 // DNS cache removals require curl 7.42 or higher
  153.                 $this->multi->reset();
  154.             }
  155.             foreach ($options['resolve'] as $host => $ip) {
  156.                 $resolve[] = null === $ip "-$host:$port"$host:$port:$ip";
  157.                 $this->multi->dnsCache->hostnames[$host] = $ip;
  158.                 $this->multi->dnsCache->removals["-$host:$port"] = "-$host:$port";
  159.             }
  160.             $curlopts[\CURLOPT_RESOLVE] = $resolve;
  161.         }
  162.         if ('POST' === $method) {
  163.             // Use CURLOPT_POST to have browser-like POST-to-GET redirects for 301, 302 and 303
  164.             $curlopts[\CURLOPT_POST] = true;
  165.         } elseif ('HEAD' === $method) {
  166.             $curlopts[\CURLOPT_NOBODY] = true;
  167.         } else {
  168.             $curlopts[\CURLOPT_CUSTOMREQUEST] = $method;
  169.         }
  170.         if ('\\' !== \DIRECTORY_SEPARATOR && $options['timeout'] < 1) {
  171.             $curlopts[\CURLOPT_NOSIGNAL] = true;
  172.         }
  173.         if (\extension_loaded('zlib') && !isset($options['normalized_headers']['accept-encoding'])) {
  174.             $options['headers'][] = 'Accept-Encoding: gzip'// Expose only one encoding, some servers mess up when more are provided
  175.         }
  176.         foreach ($options['headers'] as $header) {
  177.             if (':' === $header[-2] && \strlen($header) - === strpos($header': ')) {
  178.                 // curl requires a special syntax to send empty headers
  179.                 $curlopts[\CURLOPT_HTTPHEADER][] = substr_replace($header';', -2);
  180.             } else {
  181.                 $curlopts[\CURLOPT_HTTPHEADER][] = $header;
  182.             }
  183.         }
  184.         // Prevent curl from sending its default Accept and Expect headers
  185.         foreach (['accept''expect'] as $header) {
  186.             if (!isset($options['normalized_headers'][$header][0])) {
  187.                 $curlopts[\CURLOPT_HTTPHEADER][] = $header.':';
  188.             }
  189.         }
  190.         if (!\is_string($body $options['body'])) {
  191.             if (\is_resource($body)) {
  192.                 $curlopts[\CURLOPT_INFILE] = $body;
  193.             } else {
  194.                 $eof false;
  195.                 $buffer '';
  196.                 $curlopts[\CURLOPT_READFUNCTION] = static function ($ch$fd$length) use ($body, &$buffer, &$eof) {
  197.                     return self::readRequestBody($length$body$buffer$eof);
  198.                 };
  199.             }
  200.             if (isset($options['normalized_headers']['content-length'][0])) {
  201.                 $curlopts[\CURLOPT_INFILESIZE] = substr($options['normalized_headers']['content-length'][0], \strlen('Content-Length: '));
  202.             } elseif (!isset($options['normalized_headers']['transfer-encoding'])) {
  203.                 $curlopts[\CURLOPT_HTTPHEADER][] = 'Transfer-Encoding: chunked'// Enable chunked request bodies
  204.             }
  205.             if ('POST' !== $method) {
  206.                 $curlopts[\CURLOPT_UPLOAD] = true;
  207.                 if (!isset($options['normalized_headers']['content-type'])) {
  208.                     $curlopts[\CURLOPT_HTTPHEADER][] = 'Content-Type: application/x-www-form-urlencoded';
  209.                 }
  210.             }
  211.         } elseif ('' !== $body || 'POST' === $method) {
  212.             $curlopts[\CURLOPT_POSTFIELDS] = $body;
  213.         }
  214.         if ($options['peer_fingerprint']) {
  215.             if (!isset($options['peer_fingerprint']['pin-sha256'])) {
  216.                 throw new TransportException(__CLASS__.' supports only "pin-sha256" fingerprints.');
  217.             }
  218.             $curlopts[\CURLOPT_PINNEDPUBLICKEY] = 'sha256//'.implode(';sha256//'$options['peer_fingerprint']['pin-sha256']);
  219.         }
  220.         if ($options['bindto']) {
  221.             if (file_exists($options['bindto'])) {
  222.                 $curlopts[\CURLOPT_UNIX_SOCKET_PATH] = $options['bindto'];
  223.             } elseif (!str_starts_with($options['bindto'], 'if!') && preg_match('/^(.*):(\d+)$/'$options['bindto'], $matches)) {
  224.                 $curlopts[\CURLOPT_INTERFACE] = $matches[1];
  225.                 $curlopts[\CURLOPT_LOCALPORT] = $matches[2];
  226.             } else {
  227.                 $curlopts[\CURLOPT_INTERFACE] = $options['bindto'];
  228.             }
  229.         }
  230.         if ($options['max_duration']) {
  231.             $curlopts[\CURLOPT_TIMEOUT_MS] = 1000 $options['max_duration'];
  232.         }
  233.         if (!empty($options['extra']['curl']) && \is_array($options['extra']['curl'])) {
  234.             $this->validateExtraCurlOptions($options['extra']['curl']);
  235.             $curlopts += $options['extra']['curl'];
  236.         }
  237.         if ($pushedResponse $this->multi->pushedResponses[$url] ?? null) {
  238.             unset($this->multi->pushedResponses[$url]);
  239.             if (self::acceptPushForRequest($method$options$pushedResponse)) {
  240.                 $this->logger && $this->logger->debug(sprintf('Accepting pushed response: "%s %s"'$method$url));
  241.                 // Reinitialize the pushed response with request's options
  242.                 $ch $pushedResponse->handle;
  243.                 $pushedResponse $pushedResponse->response;
  244.                 $pushedResponse->__construct($this->multi$url$options$this->logger);
  245.             } else {
  246.                 $this->logger && $this->logger->debug(sprintf('Rejecting pushed response: "%s"'$url));
  247.                 $pushedResponse null;
  248.             }
  249.         }
  250.         if (!$pushedResponse) {
  251.             $ch curl_init();
  252.             $this->logger && $this->logger->info(sprintf('Request: "%s %s"'$method$url));
  253.             $curlopts += [\CURLOPT_SHARE => $this->multi->share];
  254.         }
  255.         foreach ($curlopts as $opt => $value) {
  256.             if (null !== $value && !curl_setopt($ch$opt$value) && \CURLOPT_CERTINFO !== $opt && (!\defined('CURLOPT_HEADEROPT') || \CURLOPT_HEADEROPT !== $opt)) {
  257.                 $constantName $this->findConstantName($opt);
  258.                 throw new TransportException(sprintf('Curl option "%s" is not supported.'$constantName ?? $opt));
  259.             }
  260.         }
  261.         return $pushedResponse ?? new CurlResponse($this->multi$ch$options$this->logger$methodself::createRedirectResolver($options$host), CurlClientState::$curlVersion['version_number']);
  262.     }
  263.     /**
  264.      * {@inheritdoc}
  265.      */
  266.     public function stream($responsesfloat $timeout null): ResponseStreamInterface
  267.     {
  268.         if ($responses instanceof CurlResponse) {
  269.             $responses = [$responses];
  270.         } elseif (!is_iterable($responses)) {
  271.             throw new \TypeError(sprintf('"%s()" expects parameter 1 to be an iterable of CurlResponse objects, "%s" given.'__METHOD__get_debug_type($responses)));
  272.         }
  273.         if (\is_resource($this->multi->handle) || $this->multi->handle instanceof \CurlMultiHandle) {
  274.             $active 0;
  275.             while (\CURLM_CALL_MULTI_PERFORM === curl_multi_exec($this->multi->handle$active)) {
  276.             }
  277.         }
  278.         return new ResponseStream(CurlResponse::stream($responses$timeout));
  279.     }
  280.     public function reset()
  281.     {
  282.         $this->multi->reset();
  283.     }
  284.     /**
  285.      * Accepts pushed responses only if their headers related to authentication match the request.
  286.      */
  287.     private static function acceptPushForRequest(string $method, array $optionsPushedResponse $pushedResponse): bool
  288.     {
  289.         if ('' !== $options['body'] || $method !== $pushedResponse->requestHeaders[':method'][0]) {
  290.             return false;
  291.         }
  292.         foreach (['proxy''no_proxy''bindto''local_cert''local_pk'] as $k) {
  293.             if ($options[$k] !== $pushedResponse->parentOptions[$k]) {
  294.                 return false;
  295.             }
  296.         }
  297.         foreach (['authorization''cookie''range''proxy-authorization'] as $k) {
  298.             $normalizedHeaders $options['normalized_headers'][$k] ?? [];
  299.             foreach ($normalizedHeaders as $i => $v) {
  300.                 $normalizedHeaders[$i] = substr($v\strlen($k) + 2);
  301.             }
  302.             if (($pushedResponse->requestHeaders[$k] ?? []) !== $normalizedHeaders) {
  303.                 return false;
  304.             }
  305.         }
  306.         return true;
  307.     }
  308.     /**
  309.      * Wraps the request's body callback to allow it to return strings longer than curl requested.
  310.      */
  311.     private static function readRequestBody(int $length\Closure $bodystring &$bufferbool &$eof): string
  312.     {
  313.         if (!$eof && \strlen($buffer) < $length) {
  314.             if (!\is_string($data $body($length))) {
  315.                 throw new TransportException(sprintf('The return value of the "body" option callback must be a string, "%s" returned.'get_debug_type($data)));
  316.             }
  317.             $buffer .= $data;
  318.             $eof '' === $data;
  319.         }
  320.         $data substr($buffer0$length);
  321.         $buffer substr($buffer$length);
  322.         return $data;
  323.     }
  324.     /**
  325.      * Resolves relative URLs on redirects and deals with authentication headers.
  326.      *
  327.      * Work around CVE-2018-1000007: Authorization and Cookie headers should not follow redirects - fixed in Curl 7.64
  328.      */
  329.     private static function createRedirectResolver(array $optionsstring $host): \Closure
  330.     {
  331.         $redirectHeaders = [];
  332.         if ($options['max_redirects']) {
  333.             $redirectHeaders['host'] = $host;
  334.             $redirectHeaders['with_auth'] = $redirectHeaders['no_auth'] = array_filter($options['headers'], static function ($h) {
  335.                 return !== stripos($h'Host:');
  336.             });
  337.             if (isset($options['normalized_headers']['authorization'][0]) || isset($options['normalized_headers']['cookie'][0])) {
  338.                 $redirectHeaders['no_auth'] = array_filter($options['headers'], static function ($h) {
  339.                     return !== stripos($h'Authorization:') && !== stripos($h'Cookie:');
  340.                 });
  341.             }
  342.         }
  343.         return static function ($chstring $locationbool $noContent) use (&$redirectHeaders) {
  344.             try {
  345.                 $location self::parseUrl($location);
  346.             } catch (InvalidArgumentException $e) {
  347.                 return null;
  348.             }
  349.             if ($noContent && $redirectHeaders) {
  350.                 $filterContentHeaders = static function ($h) {
  351.                     return !== stripos($h'Content-Length:') && !== stripos($h'Content-Type:') && !== stripos($h'Transfer-Encoding:');
  352.                 };
  353.                 $redirectHeaders['no_auth'] = array_filter($redirectHeaders['no_auth'], $filterContentHeaders);
  354.                 $redirectHeaders['with_auth'] = array_filter($redirectHeaders['with_auth'], $filterContentHeaders);
  355.             }
  356.             if ($redirectHeaders && $host parse_url('http:'.$location['authority'], \PHP_URL_HOST)) {
  357.                 $requestHeaders $redirectHeaders['host'] === $host $redirectHeaders['with_auth'] : $redirectHeaders['no_auth'];
  358.                 curl_setopt($ch\CURLOPT_HTTPHEADER$requestHeaders);
  359.             } elseif ($noContent && $redirectHeaders) {
  360.                 curl_setopt($ch\CURLOPT_HTTPHEADER$redirectHeaders['with_auth']);
  361.             }
  362.             $url self::parseUrl(curl_getinfo($ch\CURLINFO_EFFECTIVE_URL));
  363.             $url self::resolveUrl($location$url);
  364.             curl_setopt($ch\CURLOPT_PROXY$options['proxy']
  365.                 ?? ('https:' === $url['scheme'] ? $_SERVER['https_proxy'] ?? $_SERVER['HTTPS_PROXY'] ?? null null)
  366.                 // Ignore HTTP_PROXY except on the CLI to work around httpoxy set of vulnerabilities
  367.                 ?? $_SERVER['http_proxy'] ?? (\in_array(\PHP_SAPI, ['cli''phpdbg'], true) ? $_SERVER['HTTP_PROXY'] ?? null null) ?? $_SERVER['all_proxy'] ?? $_SERVER['ALL_PROXY'] ?? null
  368.             );
  369.             return implode(''$url);
  370.         };
  371.     }
  372.     private function findConstantName(int $opt): ?string
  373.     {
  374.         $constants array_filter(get_defined_constants(), static function ($v$k) use ($opt) {
  375.             return $v === $opt && 'C' === $k[0] && (str_starts_with($k'CURLOPT_') || str_starts_with($k'CURLINFO_'));
  376.         }, \ARRAY_FILTER_USE_BOTH);
  377.         return key($constants);
  378.     }
  379.     /**
  380.      * Prevents overriding options that are set internally throughout the request.
  381.      */
  382.     private function validateExtraCurlOptions(array $options): void
  383.     {
  384.         $curloptsToConfig = [
  385.             // options used in CurlHttpClient
  386.             \CURLOPT_HTTPAUTH => 'auth_ntlm',
  387.             \CURLOPT_USERPWD => 'auth_ntlm',
  388.             \CURLOPT_RESOLVE => 'resolve',
  389.             \CURLOPT_NOSIGNAL => 'timeout',
  390.             \CURLOPT_HTTPHEADER => 'headers',
  391.             \CURLOPT_INFILE => 'body',
  392.             \CURLOPT_READFUNCTION => 'body',
  393.             \CURLOPT_INFILESIZE => 'body',
  394.             \CURLOPT_POSTFIELDS => 'body',
  395.             \CURLOPT_UPLOAD => 'body',
  396.             \CURLOPT_INTERFACE => 'bindto',
  397.             \CURLOPT_TIMEOUT_MS => 'max_duration',
  398.             \CURLOPT_TIMEOUT => 'max_duration',
  399.             \CURLOPT_MAXREDIRS => 'max_redirects',
  400.             \CURLOPT_PROXY => 'proxy',
  401.             \CURLOPT_NOPROXY => 'no_proxy',
  402.             \CURLOPT_SSL_VERIFYPEER => 'verify_peer',
  403.             \CURLOPT_SSL_VERIFYHOST => 'verify_host',
  404.             \CURLOPT_CAINFO => 'cafile',
  405.             \CURLOPT_CAPATH => 'capath',
  406.             \CURLOPT_SSL_CIPHER_LIST => 'ciphers',
  407.             \CURLOPT_SSLCERT => 'local_cert',
  408.             \CURLOPT_SSLKEY => 'local_pk',
  409.             \CURLOPT_KEYPASSWD => 'passphrase',
  410.             \CURLOPT_CERTINFO => 'capture_peer_cert_chain',
  411.             \CURLOPT_USERAGENT => 'normalized_headers',
  412.             \CURLOPT_REFERER => 'headers',
  413.             // options used in CurlResponse
  414.             \CURLOPT_NOPROGRESS => 'on_progress',
  415.             \CURLOPT_PROGRESSFUNCTION => 'on_progress',
  416.         ];
  417.         if (\defined('CURLOPT_UNIX_SOCKET_PATH')) {
  418.             $curloptsToConfig[\CURLOPT_UNIX_SOCKET_PATH] = 'bindto';
  419.         }
  420.         if (\defined('CURLOPT_PINNEDPUBLICKEY')) {
  421.             $curloptsToConfig[\CURLOPT_PINNEDPUBLICKEY] = 'peer_fingerprint';
  422.         }
  423.         $curloptsToCheck = [
  424.             \CURLOPT_PRIVATE,
  425.             \CURLOPT_HEADERFUNCTION,
  426.             \CURLOPT_WRITEFUNCTION,
  427.             \CURLOPT_VERBOSE,
  428.             \CURLOPT_STDERR,
  429.             \CURLOPT_RETURNTRANSFER,
  430.             \CURLOPT_URL,
  431.             \CURLOPT_FOLLOWLOCATION,
  432.             \CURLOPT_HEADER,
  433.             \CURLOPT_CONNECTTIMEOUT,
  434.             \CURLOPT_CONNECTTIMEOUT_MS,
  435.             \CURLOPT_HTTP_VERSION,
  436.             \CURLOPT_PORT,
  437.             \CURLOPT_DNS_USE_GLOBAL_CACHE,
  438.             \CURLOPT_PROTOCOLS,
  439.             \CURLOPT_REDIR_PROTOCOLS,
  440.             \CURLOPT_COOKIEFILE,
  441.             \CURLINFO_REDIRECT_COUNT,
  442.         ];
  443.         if (\defined('CURLOPT_HTTP09_ALLOWED')) {
  444.             $curloptsToCheck[] = \CURLOPT_HTTP09_ALLOWED;
  445.         }
  446.         if (\defined('CURLOPT_HEADEROPT')) {
  447.             $curloptsToCheck[] = \CURLOPT_HEADEROPT;
  448.         }
  449.         $methodOpts = [
  450.             \CURLOPT_POST,
  451.             \CURLOPT_PUT,
  452.             \CURLOPT_CUSTOMREQUEST,
  453.             \CURLOPT_HTTPGET,
  454.             \CURLOPT_NOBODY,
  455.         ];
  456.         foreach ($options as $opt => $optValue) {
  457.             if (isset($curloptsToConfig[$opt])) {
  458.                 $constName $this->findConstantName($opt) ?? $opt;
  459.                 throw new InvalidArgumentException(sprintf('Cannot set "%s" with "extra.curl", use option "%s" instead.'$constName$curloptsToConfig[$opt]));
  460.             }
  461.             if (\in_array($opt$methodOpts)) {
  462.                 throw new InvalidArgumentException('The HTTP method cannot be overridden using "extra.curl".');
  463.             }
  464.             if (\in_array($opt$curloptsToCheck)) {
  465.                 $constName $this->findConstantName($opt) ?? $opt;
  466.                 throw new InvalidArgumentException(sprintf('Cannot set "%s" with "extra.curl".'$constName));
  467.             }
  468.         }
  469.     }
  470. }