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

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